@@ -3,18 +3,28 @@ import PropTypes from 'prop-types';
3
3
import { connect } from 'react-redux' ;
4
4
import { Helmet } from 'react-helmet' ;
5
5
import { addTodo , toggleTodo , removeTodo , fetchTodos } from 'actions/todos' ;
6
- import { Container , Header , Checkbox , List , Button , Form } from 'semantic-ui-react' ;
6
+ import {
7
+ Container ,
8
+ Header ,
9
+ Checkbox ,
10
+ List ,
11
+ Button ,
12
+ Form
13
+ } from 'semantic-ui-react' ;
7
14
import classnames from 'classnames' ;
8
15
import css from './index.scss' ;
9
16
10
17
const cx = classnames . bind ( css ) ;
11
18
12
19
class TodosContainer extends Component {
20
+ static fetchData = ( { store } ) => {
21
+ return store . dispatch ( fetchTodos ( ) ) ;
22
+ } ;
13
23
14
24
static propTypes = {
15
25
todos : PropTypes . object . isRequired ,
16
26
dispatch : PropTypes . func . isRequired
17
- }
27
+ } ;
18
28
19
29
state = { todoText : '' } ;
20
30
@@ -26,30 +36,30 @@ class TodosContainer extends Component {
26
36
}
27
37
}
28
38
29
- submitTodo = ( ev ) => {
39
+ submitTodo = ev => {
30
40
const { dispatch } = this . props ;
31
41
const { todoText } = this . state ;
32
42
33
43
ev . preventDefault ( ) ;
34
44
dispatch ( addTodo ( todoText ) ) ;
35
45
this . setState ( { todoText : '' } ) ;
36
- }
46
+ } ;
37
47
38
- checkTodo = ( id ) => {
48
+ checkTodo = id => {
39
49
const { dispatch } = this . props ;
40
50
41
51
dispatch ( toggleTodo ( id ) ) ;
42
- }
52
+ } ;
43
53
44
- removeTodo = ( id ) => {
54
+ removeTodo = id => {
45
55
const { dispatch } = this . props ;
46
56
47
57
dispatch ( removeTodo ( id ) ) ;
48
- }
58
+ } ;
49
59
50
- onTodoChange = ( ev ) => {
60
+ onTodoChange = ev => {
51
61
this . setState ( { todoText : ev . target . value } ) ;
52
- }
62
+ } ;
53
63
54
64
render ( ) {
55
65
const { todos : { todos } } = this . props ;
@@ -81,7 +91,9 @@ class TodosContainer extends Component {
81
91
onChange = { ( ) => this . checkTodo ( id ) }
82
92
/>
83
93
</ List . Content >
84
- < List . Content className = { cx ( css . text , { [ css . completed ] : completed } ) } >
94
+ < List . Content
95
+ className = { cx ( css . text , { [ css . completed ] : completed } ) }
96
+ >
85
97
{ text }
86
98
</ List . Content >
87
99
</ List . Item >
@@ -94,7 +106,8 @@ class TodosContainer extends Component {
94
106
onChange = { this . onTodoChange }
95
107
value = { todoText }
96
108
type = "text"
97
- placeholder = "Add a todo..." />
109
+ placeholder = "Add a todo..."
110
+ />
98
111
< Form . Button content = "Add" icon = "plus" />
99
112
</ Form . Group >
100
113
</ Form >
@@ -103,10 +116,6 @@ class TodosContainer extends Component {
103
116
}
104
117
}
105
118
106
- TodosContainer . fetchData = ( { store } ) => {
107
- return store . dispatch ( fetchTodos ( ) ) ;
108
- } ;
109
-
110
119
const mapStateToProps = ( { todos } ) => ( { todos } ) ;
111
120
112
121
export default connect ( mapStateToProps ) ( TodosContainer ) ;
0 commit comments