@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22import PropTypes from 'prop-types' ;
33import { connect } from 'react-redux' ;
44import { addTodo , toggleTodo , removeTodo } from 'actions/todos' ;
5+ import { Container , Header , Checkbox , List , Button , Form } from 'semantic-ui-react' ;
56import classnames from 'classnames' ;
67import css from './index.scss' ;
78
@@ -14,13 +15,15 @@ class TodosContainer extends Component {
1415 dispatch : PropTypes . func . isRequired
1516 }
1617
18+ state = { todoText : null } ;
19+
1720 submitTodo = ( ev ) => {
1821 const { dispatch } = this . props ;
19- const { todoText } = this . refs ;
22+ const { todoText } = this . state ;
2023
2124 ev . preventDefault ( ) ;
22- dispatch ( addTodo ( todoText . value ) ) ;
23- todoText . value = '' ;
25+ dispatch ( addTodo ( todoText ) ) ;
26+ this . setState ( { todoText : '' } ) ;
2427 }
2528
2629 checkTodo = ( id ) => {
@@ -35,32 +38,51 @@ class TodosContainer extends Component {
3538 dispatch ( removeTodo ( id ) ) ;
3639 }
3740
41+ onTodoChange = ( ev ) => {
42+ this . setState ( { todoText : ev . target . value } ) ;
43+ }
44+
3845 render ( ) {
3946 const { todos } = this . props ;
47+ const { todoText } = this . state ;
4048
4149 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 } >
4553 { todos . map ( ( todo , idx ) => {
4654 const { id, text, completed } = todo ;
4755
4856 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 >
5672 ) ;
5773 } ) }
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 >
6486 ) ;
6587 }
6688}
0 commit comments