simplify 2-2 exercise

This commit is contained in:
Ken
2019-02-28 14:09:25 -08:00
parent 88425249ea
commit f6d185632c
7 changed files with 239 additions and 40 deletions

View File

@@ -1,13 +1,27 @@
import React from 'react';
import { Stack } from 'office-ui-fabric-react';
import { TodoListItem } from './TodoListItem';
import { Store, FilterTypes } from '../store';
interface TodoListProps {
complete: (id: string) => void;
remove: (id: string) => void;
todos: Store['todos'];
filter: FilterTypes;
edit: (id: string, label: string) => void;
}
export const TodoList = (props: TodoListProps) => {
const { filter, todos, complete, remove, edit } = props;
const filteredTodos = Object.keys(todos).filter(id => {
return filter === 'all' || (filter === 'completed' && todos[id].completed) || (filter === 'active' && !todos[id].completed);
});
export const TodoList = (props: any) => {
return (
<ul className="todos">
<TodoListItem />
<TodoListItem />
<TodoListItem />
</ul>
<Stack gap={10}>
{filteredTodos.map(id => (
<TodoListItem key={id} id={id} todos={todos} complete={complete} remove={remove} edit={edit} />
))}
</Stack>
);
};