Skip to content

Commit bcafed4

Browse files
author
Chong Guo
committed
updated most of the components and containers & updated reducers and actions & added redux-dev-tools
1 parent b1875ad commit bcafed4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1106
-1065
lines changed

LICENSE

Lines changed: 21 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,40 @@
33

44
## Stack
55

6-
- [x] [express](http://expressjs.com/) as backend
7-
- [x] [yarn](https://github.com/yarnpkg/yarn) as dependency manager
8-
- [x] [gulp](https://github.com/gulpjs/gulp) as task runner
9-
- [x] [materialize](http://materializecss.com/) a modern responsive front-end framework based on Material Design
10-
- [x] [webpack 2](https://github.com/webpack/webpack) as module bundler
11-
- [x] [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) offers a dev middleware for webpack, which arguments a live bundle to a directory
12-
- [x] [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware) add hot reloading into an existing server without [webpack-dev-server](https://github.com/webpack/webpack-dev-server)
6+
- [x] [express](http://expressjs.com/) - backend
7+
- [x] [yarn](https://github.com/yarnpkg/yarn) - dependency manager
8+
- [x] [gulp](https://github.com/gulpjs/gulp) - task runner
9+
- [x] [materialize](http://materializecss.com/) - a modern responsive front-end framework based on Material Design
10+
- [x] [sass](https://github.com/sass/sass) - CSS pre-processors
11+
- [x] [postcss](https://github.com/postcss/postcss) - CSS post-processor
12+
- [x] [webpack 2](https://github.com/webpack/webpack) - module bundler
13+
- [x] [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) - offers a dev middleware for webpack, which arguments a live bundle to a directory
14+
- [x] [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware) - add hot reloading into an existing server without [webpack-dev-server](https://github.com/webpack/webpack-dev-server)
1315
- [x] followed [ES6 standard](https://github.com/lukehoban/es6features)
14-
- [x] [babel](https://babeljs.io/) as ES6 to ES5 compiler
15-
- [x] [react](https://facebook.github.io/react/) for building user interfaces.
16-
- [x] [react-router](https://github.com/ReactTraining/react-router) for routing
17-
- [x] [react-redux](https://github.com/reactjs/react-redux) the official react bindings for [redux](https://github.com/reactjs/redux) (a predictable state container for js apps)
18-
- [x] [react-router-redux](https://github.com/reactjs/react-router-redux) to keep react-router and redux in sync
19-
- [x] [typescript](https://github.com/Microsoft/TypeScript) let's write future javascript => now!
20-
- [x] [react-hot-loader 3](https://github.com/gaearon/react-hot-loader) for hot module reload!
21-
- [x] [editorconfig](http://editorconfig.org/) to maintain consistent coding styles between different editors and IDEs
22-
- [x] [eslint](http://eslint.org/) to lint javascript files (.js, .jsx)
23-
- [x] [tslint](https://palantir.github.io/tslint/) to lint typescript files (.ts, .tsx)
24-
- [x] [stylelint](https://stylelint.io/) to lint style files (.css, .scss)
25-
- [x] [prismjs](https://github.com/PrismJS/prism) for code syntax highlight
26-
- [ ] [jest](https://facebook.github.io/jest/) for testing
27-
- [ ] [istanbul](https://github.com/gotwarlost/istanbul) for test coverage
16+
- [x] [babel](https://babeljs.io/) - compile ES6 to ES5
17+
- [x] [react](https://facebook.github.io/react/) - building user interfaces
18+
- [x] [react-hot-loader 3](https://github.com/gaearon/react-hot-loader) - hot module reload!
19+
- [x] [react-router](https://github.com/ReactTraining/react-router) - routing
20+
- [x] [react-redux](https://github.com/reactjs/react-redux) - the official react bindings for [redux](https://github.com/reactjs/redux) (a predictable state container for js apps)
21+
- [x] [react-router-redux](https://github.com/reactjs/react-router-redux) - keep react-router and redux in sync
22+
- [x] [typescript](https://github.com/Microsoft/TypeScript) - a typed superset of javascript that scales
23+
- [x] [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) - high quality TypeScript type definitions
24+
- [x] [editorconfig](http://editorconfig.org/) - maintain consistent coding styles between different editors and IDEs
25+
- [x] [eslint](http://eslint.org/) - lint javascript files (.js, .jsx)
26+
- [x] [tslint](https://palantir.github.io/tslint/) - lint typescript files (.ts, .tsx)
27+
- [x] [stylelint](https://stylelint.io/) - lint style files (.css, .scss)
28+
- [x] [postgresql](https://www.postgresql.org/) - advanced open source database
29+
- [x] [prismjs](https://github.com/PrismJS/prism) - code syntax highlight
30+
- [ ] [jest](https://facebook.github.io/jest/) - testing
31+
- [ ] [istanbul](https://github.com/gotwarlost/istanbul) - test coverage
2832

2933
## Install && Run
3034

3135
### Prerequisite
3236

3337
* `node`
3438
* `yarn` (recommended) or `npm`
35-
* `postgresql` (or other database if you want)
39+
* `postgresql` or other database
3640

3741
Install [yarn](https://yarnpkg.com/en/docs/install#linux-tab) follows official documentation.
3842

@@ -61,7 +65,7 @@ gulp
6165
**On production (with uglify-js and other optimazitions):**
6266

6367
```bash
64-
gulp --env production
68+
NODE_ENV=production gulp
6569
```
6670

6771

@@ -77,4 +81,4 @@ Check my [another boilerplate](https://github.com/Armour/Django-Webpack-React-Ty
7781

7882
### License
7983

80-
GPL-3.0 License
84+
MIT License

backend/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import webpack from 'webpack';
99
import webpackDevMiddleware from 'webpack-dev-middleware';
1010
import webpackHotMiddleware from 'webpack-hot-middleware';
1111
import webpackConfig from '../webpack.config.dev.babel';
12+
1213
import config from './config.json';
1314

1415
import api from './routes/api';
1516

16-
const isDev = process.env.NODE_ENV !== 'production';
17+
const isProduction = process.env.NODE_ENV === 'production';
1718
const port = config.http_port;
1819
const app = express();
1920

@@ -25,7 +26,7 @@ app.use(cookieParser());
2526
// Api router
2627
app.use('/api', api);
2728

28-
if (isDev) {
29+
if (!isProduction) {
2930
const compiler = webpack(webpackConfig);
3031
const middleware = webpackDevMiddleware(compiler, {
3132
// The public URL of the output resource directory (CDN), should be the same as output.publicPath

frontend/src/App.tsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
import React from 'react';
22
import { Provider } from 'react-redux';
3-
import { Router, browserHistory } from 'react-router';
4-
import { routerReducer, syncHistoryWithStore } from 'react-router-redux';
5-
import { combineReducers, createStore } from 'redux';
3+
import { Router } from 'react-router';
64

5+
import DevTools from 'containers/DevTools';
76
import routes from 'router';
7+
import { isProduction } from 'utils';
88

99
import 'image/favicon.ico';
1010
import 'js/bin/materialize.min';
1111
import 'sass/index.scss';
1212

13-
// Add the reducer to your store on the `routing` key
14-
const store = createStore(
15-
combineReducers({
16-
// ...reducers,
17-
routing: routerReducer,
18-
}),
19-
);
20-
21-
// Create an enhanced history that syncs navigation events with the store
22-
const history = syncHistoryWithStore(browserHistory, store);
23-
2413
// Set the store, history and routers
25-
export default () => {
26-
return (
27-
<Provider store={store}>
28-
<Router history={history} routes={routes}/>
29-
</Provider>
30-
);
31-
};
14+
export default class App extends React.Component<any, any> {
15+
public render() {
16+
return (
17+
<Provider store={this.props.store}>
18+
<div>
19+
<Router history={this.props.history} routes={routes}/>
20+
{!isProduction && <DevTools />}
21+
</div>
22+
</Provider>
23+
);
24+
}
25+
}

frontend/src/actions/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'actions/todoList';

frontend/src/actions/todoList.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ADD_TODO, SET_VISIBILITY_FILTER, TOGGLE_TODO } from 'constants/actionTypes';
2+
import { IActionAddTodo, IActionSetVisibilityFilter, IActionToggleTodo, IVisibilityFilterOptions } from 'types';
3+
import { v1 } from 'uuid';
4+
5+
export const addTodo = (text: string): IActionAddTodo => {
6+
return {
7+
type: ADD_TODO,
8+
id: v1(),
9+
text,
10+
completed: false,
11+
};
12+
};
13+
14+
export const toggleTodo = (id: string): IActionToggleTodo => {
15+
return {
16+
type: TOGGLE_TODO,
17+
id,
18+
};
19+
};
20+
21+
export const setVisibilityFilter = (filter: IVisibilityFilterOptions): IActionSetVisibilityFilter => {
22+
return {
23+
type: SET_VISIBILITY_FILTER,
24+
filter,
25+
};
26+
};

frontend/src/components/Carousel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22

3-
import { TOAST_DISPLAY_DURATION, TOOLTIP_DELAY_TIME } from 'constants/Timers';
3+
import { TOAST_DISPLAY_DURATION, TOOLTIP_DELAY_TIME } from 'constants/timers';
44

55
interface ICarouselProps {}
66

77
interface ICarouselState {}
88

9-
let tooltipConfig: Materialize.TooltipOptions = {
9+
const tooltipConfig: Materialize.TooltipOptions = {
1010
delay: TOOLTIP_DELAY_TIME,
1111
position: 'top',
1212
tooltip: 'Click Me! >. <',

frontend/src/components/Dropdown.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22

33
import NavLink from 'components/NavLink';
4-
5-
import { upperCaseFirstChar } from 'utils/index';
4+
import { upperCaseFirstChar } from 'utils';
65

76
interface IDropdownProps {
87
id: string;
@@ -17,10 +16,9 @@ class Dropdown extends React.Component<IDropdownProps, IDropdownState> {
1716
}
1817

1918
public render() {
20-
const links = [];
21-
for (const key of this.props.dropdownLists) {
22-
links.push(<li key={key}><NavLink to={`/${key}`}>{upperCaseFirstChar(key)}</NavLink></li>);
23-
}
19+
const links = this.props.dropdownLists.map(key =>
20+
<li key={key}><NavLink to={`/${key}`}>{upperCaseFirstChar(key)}</NavLink></li>,
21+
);
2422
return (
2523
<ul id={this.props.id} className="dropdown-content">
2624
{links}

frontend/src/components/Header.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ interface IHeaderState {
1313
class Header extends React.Component<IHeaderProps, IHeaderState> {
1414
constructor(props: IHeaderProps) {
1515
super(props);
16-
this.state = {dropdownLists: ['parallax'], dropdownId: 'header-dropdown'};
16+
this.state = {
17+
dropdownLists: ['parallax'],
18+
dropdownId: 'header-dropdown',
19+
};
1720
}
1821

1922
public render() {

frontend/src/components/NavLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface INavLinkState {}
88
class NavLink extends React.Component<INavLinkProps, INavLinkState> {
99
public render() {
1010
return (
11-
<Link {...this.props} activeClassName="active"/>
11+
<Link {...this.props} activeClassName="active-link"/>
1212
);
1313
}
1414
}

frontend/src/components/PrismCodes.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ interface IPrismCodesState {
1111
}
1212

1313
class PrismCodes extends React.Component<IPrismCodesProps, IPrismCodesState> {
14-
constructor(props: IPrismCodesProps) {
15-
super(props);
16-
this.highlightCode = this.highlightCode.bind(this);
17-
}
18-
1914
public highlightCode = (code: Element) => {
2015
this.setState({ code }, () => {
2116
Prism.highlightElement(this.state.code, false);

frontend/src/components/Pushpin.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React from 'react';
22

3-
import { upperCaseFirstChar } from 'utils/index';
3+
import { upperCaseFirstChar } from 'utils';
44

55
const pushpinStyle = {
66
top: '0px',
77
};
88

9-
interface IPushipinProps {
9+
interface IPushpinProps {
1010
color: string;
1111
}
1212

13-
interface IPushipinState {}
13+
interface IPushpinState {}
1414

15-
class Pushipin extends React.Component<IPushipinProps, IPushipinState> {
15+
class Pushpin extends React.Component<IPushpinProps, IPushpinState> {
1616
public render() {
1717
return (
1818
<div id={this.props.color} className={`block ${this.props.color} lighten-1`}>
@@ -32,4 +32,4 @@ class Pushipin extends React.Component<IPushipinProps, IPushipinState> {
3232
}
3333
}
3434

35-
export default Pushipin;
35+
export default Pushpin;

frontend/src/components/Todo.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
3+
import { ITodoModel } from 'types';
4+
5+
interface ITodoProps extends ITodoModel {
6+
onClick: () => void;
7+
}
8+
9+
interface ITodoState {}
10+
11+
class Todo extends React.Component<ITodoProps, ITodoState> {
12+
public render() {
13+
return (
14+
<li onClick={this.props.onClick} style={{ textDecoration: this.props.completed ? 'line-through' : 'none' }}>
15+
{this.props.text}
16+
</li>
17+
);
18+
}
19+
}
20+
21+
export default Todo;

frontend/src/components/TodoApp.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
import TodoFooter from 'components/TodoFooter';
4+
import AddTodo from 'containers/AddTodo';
5+
import VisibleTodoList from 'containers/VisibleTodoList';
6+
7+
interface ITodoAppProps {}
8+
9+
interface ITodoAppState {}
10+
11+
class TodoApp extends React.Component<ITodoAppProps, ITodoAppState> {
12+
public render() {
13+
return (
14+
<div>
15+
<AddTodo />
16+
<VisibleTodoList />
17+
<TodoFooter />
18+
</div>
19+
);
20+
}
21+
}
22+
23+
export default TodoApp;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
3+
import FilterLink from 'containers/FilterLink';
4+
5+
interface ITodoFooterProps {}
6+
7+
interface ITodoFooterState {}
8+
9+
class TodoFooter extends React.Component<ITodoFooterProps, ITodoFooterState> {
10+
public render() {
11+
return (
12+
<p>
13+
Show:
14+
{' '}
15+
<FilterLink filter="SHOW_ALL">
16+
All
17+
</FilterLink>
18+
{', '}
19+
<FilterLink filter="SHOW_ACTIVE">
20+
Active
21+
</FilterLink>
22+
{', '}
23+
<FilterLink filter="SHOW_COMPLETED">
24+
Completed
25+
</FilterLink>
26+
</p>
27+
);
28+
}
29+
}
30+
31+
export default TodoFooter;

frontend/src/components/TodoInput.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
3+
export interface ITodoInputStateProps {}
4+
5+
export interface ITodoInputDispatchProps {
6+
onSubmit: (inputValue: string) => void;
7+
}
8+
9+
type ITodoInputProps = ITodoInputStateProps & ITodoInputDispatchProps;
10+
11+
interface ITodoInputState {}
12+
13+
let input: HTMLInputElement;
14+
15+
class TodoInput extends React.Component<ITodoInputProps, ITodoInputState> {
16+
public onSubmit = (e: React.FormEvent<HTMLFormElement>): void => {
17+
e.preventDefault();
18+
if (!input.value.trim()) {
19+
return;
20+
}
21+
this.props.onSubmit(input.value);
22+
input.value = '';
23+
}
24+
25+
public setInput = (node: HTMLInputElement): void => {
26+
input = node;
27+
}
28+
29+
public render() {
30+
return (
31+
<div>
32+
<form onSubmit={this.onSubmit}>
33+
<input ref={this.setInput}/>
34+
<button type="submit">
35+
Add Todo
36+
</button>
37+
</form>
38+
</div>
39+
);
40+
}
41+
}
42+
43+
export default TodoInput;

0 commit comments

Comments
 (0)