@@ -2,6 +2,7 @@ import React, { Component } from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import { connect } from 'react-redux' ;
4
4
import { addTodo , toggleTodo , removeTodo } from 'actions/todos' ;
5
+ import { Container , Header , Checkbox , List , Button , Form } from 'semantic-ui-react' ;
5
6
import classnames from 'classnames' ;
6
7
import css from './index.scss' ;
7
8
@@ -14,13 +15,15 @@ class TodosContainer extends Component {
14
15
dispatch : PropTypes . func . isRequired
15
16
}
16
17
18
+ state = { todoText : null } ;
19
+
17
20
submitTodo = ( ev ) => {
18
21
const { dispatch } = this . props ;
19
- const { todoText } = this . refs ;
22
+ const { todoText } = this . state ;
20
23
21
24
ev . preventDefault ( ) ;
22
- dispatch ( addTodo ( todoText . value ) ) ;
23
- todoText . value = '' ;
25
+ dispatch ( addTodo ( todoText ) ) ;
26
+ this . setState ( { todoText : '' } ) ;
24
27
}
25
28
26
29
checkTodo = ( id ) => {
@@ -35,32 +38,51 @@ class TodosContainer extends Component {
35
38
dispatch ( removeTodo ( id ) ) ;
36
39
}
37
40
41
+ onTodoChange = ( ev ) => {
42
+ this . setState ( { todoText : ev . target . value } ) ;
43
+ }
44
+
38
45
render ( ) {
39
46
const { todos } = this . props ;
47
+ const { todoText } = this . state ;
40
48
41
49
return (
42
- < div >
43
- < h1 > To-Dos</ h1 >
44
- < div className = { css . todos } >
50
+ < Container >
51
+ < Header > To-Dos</ Header >
52
+ < List divided className = { css . todos } >
45
53
{ todos . map ( ( todo , idx ) => {
46
54
const { id, text, completed } = todo ;
47
55
48
56
return (
49
- < li key = { idx } className = { css . todo } >
50
- < span className = { css . completeInput } >
51
- < input type = "checkbox" onChange = { ( ) => this . checkTodo ( id ) } />
52
- </ span >
53
- < span className = { cx ( css . text , { [ css . completed ] : completed } ) } > { text } </ span >
54
- < a onClick = { ( ) => this . removeTodo ( id ) } className = { css . delete } > Remove</ a >
55
- </ li >
57
+ < List . Item key = { idx } className = { classnames ( css . todo , css . extra ) } >
58
+ < List . Content floated = "right" >
59
+ < Button
60
+ onClick = { ( ) => this . removeTodo ( id ) }
61
+ icon = "remove"
62
+ size = "mini"
63
+ />
64
+ </ List . Content >
65
+ < List . Content floated = "left" >
66
+ < Checkbox type = "checkbox" onChange = { ( ) => this . checkTodo ( id ) } />
67
+ </ List . Content >
68
+ < List . Content className = { cx ( css . text , { [ css . completed ] : completed } ) } >
69
+ { text }
70
+ </ List . Content >
71
+ </ List . Item >
56
72
) ;
57
73
} ) }
58
- </ div >
59
- < form className = { css . todoForm } onSubmit = { this . submitTodo } >
60
- < input ref = "todoText" type = "text" placeholder = "Add a todo..." />
61
- < button type = "submit" > Add</ button >
62
- </ form >
63
- </ div >
74
+ </ List >
75
+ < Form className = { css . todoForm } onSubmit = { this . submitTodo } >
76
+ < Form . Group >
77
+ < Form . Input
78
+ onChange = { this . onTodoChange }
79
+ value = { todoText }
80
+ type = "text"
81
+ placeholder = "Add a todo..." />
82
+ < Form . Button content = "Add" icon = "plus" />
83
+ </ Form . Group >
84
+ </ Form >
85
+ </ Container >
64
86
) ;
65
87
}
66
88
}
0 commit comments