import React from 'react'; import { Stack, Customizer, mergeStyles, getTheme } from 'office-ui-fabric-react'; import { TodoFooter } from './TodoFooter'; import { TodoHeader } from './TodoHeader'; import { TodoList } from './TodoList'; import { Store } from '../store'; import { FluentCustomizations } from '@uifabric/fluent-theme'; let index = 0; const className = mergeStyles({ padding: 25, ...getTheme().effects.elevation4 }); export class TodoApp extends React.Component { constructor(props) { super(props); this.state = { todos: {}, filter: 'all' }; } render() { const { filter, todos } = this.state; return ( ); } private _addTodo = label => { const { todos } = this.state; const id = index++; this.setState({ todos: { ...todos, [id]: { label } } }); }; private _remove = id => { const newTodos = { ...this.state.todos }; delete newTodos[id]; this.setState({ todos: newTodos }); }; private _complete = id => { const newTodos = { ...this.state.todos }; newTodos[id].completed = !newTodos[id].completed; this.setState({ todos: newTodos }); }; private _edit = (id, label) => { const newTodos = { ...this.state.todos }; newTodos[id] = { ...newTodos[id], label }; this.setState({ todos: newTodos }); }; private _clear = () => { const { todos } = this.state; const newTodos = {}; Object.keys(this.state.todos).forEach(id => { if (!todos[id].completed) { newTodos[id] = todos[id]; } }); this.setState({ todos: newTodos }); }; private _setFilter = filter => { this.setState({ filter: filter }); }; }