-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
executable file
·107 lines (101 loc) · 3.21 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { useEffect } from "react";
import classnames from "classnames";
import useType from "@microstates/react";
import { map, valueOf } from "microstates";
import TodoMVC from "@microstates/todomvc";
import TodoTextInput from "./TodoTextInput";
const pluralize = (word, count) => (count === 1 ? word : `${word}s`);
export default function App({ value, onChange }) {
let $ = useType(TodoMVC, value);
useEffect(() => onChange(valueOf($)), [valueOf($)]);
return (
<div className="todoapp">
<header className="header">
<h1>todos</h1>
<TodoTextInput
text={$.newTodo.state}
classes="new-todo"
onSave={$.insertNewTodo}
onBlur={$.insertNewTodo}
onInputChange={$.newTodo.set}
placeholder="What needs to be done?"
/>
</header>
<section className="main">
{$.hasTodos && (
<span>
<input
id="toggle-all"
className="toggle-all"
type="checkbox"
checked={$.isAllComplete}
onChange={$.toggleAll}
/>
<label htmlFor="toggle-all" />
</span>
)}
<ul className="todo-list">
{map($.filtered, todo => (
<li
className={classnames({
completed: todo.completed.state,
editing: todo.editing.state
})}
key={todo.id.state}
>
{todo.editing.state ? (
<TodoTextInput
text={todo.text.state}
classes="edit"
onSave={todo.save}
onBlur={todo.save}
onInputChange={todo.text.set}
/>
) : (
<div className="view">
<input
className="toggle"
type="checkbox"
checked={todo.completed.state}
onChange={todo.completed.toggle}
/>
<label onDoubleClick={todo.edit}>{todo.text.state}</label>
<button
className="destroy"
onClick={() => $.todos.remove(todo)}
/>
</div>
)}
</li>
))}
</ul>
{$.hasTodos && (
<footer className="footer">
<span className="todo-count">
<strong>{$.active.length || "No"}</strong>{" "}
{pluralize("item", $.active.length)}
</span>
<ul className="filters">
{$.filters.map(filter => (
<li key={filter.key}>
<button
className={classnames({ selected: filter.selected })}
style={{ cursor: "pointer" }}
onClick={filter.select}
>
{filter.label}
</button>
</li>
))}
</ul>
{$.hasCompleted && (
<button className="clear-completed" onClick={$.clearCompleted}>
Clear completed
</button>
)}
</footer>
)}
</section>
</div>
);
}