File tree Expand file tree Collapse file tree 6 files changed +62
-16
lines changed Expand file tree Collapse file tree 6 files changed +62
-16
lines changed Original file line number Diff line number Diff line change @@ -18,19 +18,17 @@ export function reloadTodos() {
18
18
// axios("http://someurl.com/somedataendpoint").then((data) => {
19
19
// console.log("got the data!", data);
20
20
// })
21
- dispatcher . dispatch ( { type : "FETCH_TODOS" } ) ;
22
- setTimeout ( ( ) => {
23
- dispatcher . dispatch ( { type : "RECEIVE_TODOS" , todos : [
24
- {
25
- id : 8484848484 ,
26
- text : "Go Shopping Again" ,
27
- complete : false
28
- } ,
29
- {
30
- id : 6262627272 ,
31
- text : "Hug Wife" ,
32
- complete : true
33
- } ,
34
- ] } ) ;
35
- } , 1000 ) ;
21
+ // dispatcher.dispatch({type: "FETCH_TODOS"});
22
+ dispatcher . dispatch ( { type : "RECEIVE_TODOS" , todos : [
23
+ {
24
+ id : 8484848484 ,
25
+ text : "Go Shopping Again" ,
26
+ complete : false
27
+ } ,
28
+ {
29
+ id : 6262627272 ,
30
+ text : "Hug Wife" ,
31
+ complete : true
32
+ } ,
33
+ ] } ) ;
36
34
}
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
3
+ import * as TodoActions from "../actions/TodoActions" ;
4
+
3
5
export default class Todo extends React . Component {
4
6
constructor ( props ) {
5
7
super ( ) ;
6
8
}
7
9
10
+ removeTodo ( e ) {
11
+ // console.log(this.props.id);
12
+ //REMOVE BY ID
13
+ TodoActions . deleteTodo ( this . props . id ) ;
14
+ }
15
+
8
16
render ( ) {
9
17
const { complete, edit, text } = this . props ;
10
18
@@ -20,8 +28,8 @@ export default class Todo extends React.Component {
20
28
21
29
return (
22
30
< li >
31
+ < button onClick = { this . removeTodo . bind ( this ) } > { icon } </ button >
23
32
< span > { text } </ span >
24
- < span > { icon } </ span >
25
33
</ li >
26
34
) ;
27
35
}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import Nav from "../components/layout/Nav";
7
7
export default class Layout extends React . Component {
8
8
render ( ) {
9
9
const { location } = this . props ;
10
+
10
11
const containerStyle = {
11
12
marginTop : "60px"
12
13
} ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export default class Todos extends React.Component {
11
11
this . getTodos = this . getTodos . bind ( this ) ;
12
12
this . state = {
13
13
todos : TodoStore . getAll ( ) ,
14
+ newTodo : ""
14
15
} ;
15
16
}
16
17
@@ -32,6 +33,18 @@ export default class Todos extends React.Component {
32
33
TodoActions . reloadTodos ( ) ;
33
34
}
34
35
36
+ // Start Anna Code
37
+ addTodo ( e ) {
38
+ e . preventDefault ( ) ;
39
+ TodoActions . createTodo ( this . state . newTodo ) ;
40
+ this . setState ( { newTodo : "" } ) ;
41
+ }
42
+
43
+ handleChange ( e ) {
44
+ this . setState ( { newTodo : e . target . value } ) ;
45
+ }
46
+ // End Anna Code
47
+
35
48
render ( ) {
36
49
const { todos } = this . state ;
37
50
@@ -43,6 +56,10 @@ export default class Todos extends React.Component {
43
56
< div >
44
57
< button onClick = { this . reloadTodos . bind ( this ) } > Reload!</ button >
45
58
< h1 > Todos</ h1 >
59
+ < form >
60
+ < input type = "text" value = { this . state . newTodo } onChange = { this . handleChange . bind ( this ) } />
61
+ < button onClick = { this . addTodo . bind ( this ) } > Add Todo</ button >
62
+ </ form >
46
63
< ul > { TodoComponents } </ ul >
47
64
</ div >
48
65
) ;
Original file line number Diff line number Diff line change @@ -27,7 +27,13 @@ class TodoStore extends EventEmitter {
27
27
text,
28
28
complete : false ,
29
29
} ) ;
30
+ this . emit ( "change" ) ;
31
+ }
30
32
33
+ deleteTodo ( id ) {
34
+ this . todos = this . todos . filter ( ( entry ) => {
35
+ return entry . id !== id ;
36
+ } ) ;
31
37
this . emit ( "change" ) ;
32
38
}
33
39
@@ -39,13 +45,19 @@ class TodoStore extends EventEmitter {
39
45
switch ( action . type ) {
40
46
case "CREATE_TODO" : {
41
47
this . createTodo ( action . text ) ;
48
+ this . emit ( "change" ) ;
42
49
break ;
43
50
}
44
51
case "RECEIVE_TODOS" : {
45
52
this . todos = action . todos ;
46
53
this . emit ( "change" ) ;
47
54
break ;
48
55
}
56
+ case "DELETE_TODO" : {
57
+ this . deleteTodo ( action . id ) ;
58
+ this . emit ( "change" ) ;
59
+ break ;
60
+ }
49
61
}
50
62
}
51
63
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Test</ title >
6
+ </ head >
7
+ < body >
8
+ < input type ="text " name ="" value ="">
9
+ </ body >
10
+ </ html >
You can’t perform that action at this time.
0 commit comments