1
1
import { TodoItem , ITodoItem } from '../model/TodoItem'
2
2
import * as React from 'react'
3
- import { observer } from 'mobx-react'
4
- import { ITodoList } from '../store/TodoList'
3
+ import { observer , inject } from 'mobx-react'
4
+ import { ITodoList , FILTER } from '../store/TodoList'
5
5
6
6
7
7
@@ -18,24 +18,34 @@ const TodoItemView = observer(({todo}: { todo: ITodoItem }) => {
18
18
19
19
} )
20
20
21
-
22
21
@observer
23
- export class TodoListView extends React . Component < { todoList : ITodoList < ITodoItem > } , { } > {
24
- public constructor ( props : ITodoList < ITodoItem > ) {
22
+ export class TodoListView extends React . Component < { todoList : any } , { } > {
23
+ public constructor ( props ) {
25
24
super ( props )
26
25
}
27
26
public render ( ) {
28
27
return (
29
28
< div >
30
29
< ul >
31
- {
32
- this . props . todoList . todos . map ( todo => (
33
- < TodoItemView todo = { todo } key = { todo . id } />
34
- ) )
35
- }
30
+ { this . generateTodos ( ) }
36
31
</ ul >
37
- Tasks Left : { this . props . todoList . unfinishedTodoCount }
38
32
</ div >
39
33
)
40
34
}
35
+ private generateTodos ( ) {
36
+ switch ( this . props . todoList . filter ) {
37
+ case FILTER . ALL :
38
+ return this . props . todoList . todos . map ( todo =>
39
+ < TodoItemView todo = { todo } key = { todo . id } />
40
+ )
41
+ case FILTER . ACTIVE :
42
+ return this . props . todoList . todos . filter ( todo => todo . finished == false ) . map ( todo =>
43
+ < TodoItemView todo = { todo } key = { todo . id } />
44
+ )
45
+ case FILTER . COMPLETED :
46
+ return this . props . todoList . todos . filter ( todo => todo . finished == true ) . map ( todo =>
47
+ < TodoItemView todo = { todo } key = { todo . id } />
48
+ )
49
+ }
50
+ }
41
51
}
0 commit comments