-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
274 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Filter from "./Filter"; | ||
import { addTodo, clearCompleted } from "./todos/actions"; | ||
import { useZeroDone } from "./todos"; | ||
import ToggleAll from "./ToggleAll"; | ||
|
||
export default function Actions() { | ||
return ( | ||
<div className="flex gap-1"> | ||
<ToggleAll /> | ||
<Filter /> | ||
<AddTodo /> | ||
<ClearCompleted /> | ||
</div> | ||
); | ||
} | ||
|
||
function AddTodo() { | ||
return ( | ||
<button onClick={addTodo} title="Add new todo"> | ||
+ | ||
</button> | ||
); | ||
} | ||
|
||
function ClearCompleted() { | ||
return ( | ||
<button | ||
onClick={clearCompleted} | ||
disabled={useZeroDone()} | ||
title="Delete all completed todos" | ||
> | ||
✂️ | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { filters, setFilter } from "./todos/filter"; | ||
|
||
// The component to filter the todos. | ||
export default function Filter() { | ||
return ( | ||
<select onChange={(e) => setFilter(e.target.value)}> | ||
{filters.map((f) => ( | ||
<option key={f}>{f}</option> | ||
))} | ||
</select> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useLeftCount } from "./todos"; | ||
|
||
export default function Title() { | ||
return <h3>Todo App ({useLeftCount()} todos left)</h3>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { delTodo, toggleTodo, updateTodo, useTodo } from "./todos"; | ||
|
||
// The component to display a todo. | ||
export default function TodoItem({ id }: { id: number }) { | ||
const { done, text } = useTodo(id); | ||
|
||
return ( | ||
<div className="flex gap-1 my-1"> | ||
<input type="checkbox" checked={done} onChange={() => toggleTodo(id)} /> | ||
|
||
<input | ||
placeholder="Input text here" | ||
value={text} | ||
onChange={(e) => updateTodo(id, e.target.value)} | ||
disabled={done} | ||
autoFocus | ||
/> | ||
|
||
<button onClick={() => delTodo(id)} title="Delete current todo"> | ||
✕ | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useTodoIds } from "./todos"; | ||
import TodoItem from "./TodoItem"; | ||
|
||
// The component to display all filtered todos. | ||
export default function Todos() { | ||
return ( | ||
<> | ||
{useTodoIds().map((id) => { | ||
return <TodoItem key={id} id={id} />; | ||
})} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { toggleAll, useToggleAll } from "./todos/actions"; | ||
import { useZeroCount } from "./todos"; | ||
|
||
// The component to toggle all todos. | ||
export default function ToggleAll() { | ||
return ( | ||
<input | ||
type="checkbox" | ||
checked={useToggleAll()} | ||
onChange={toggleAll} | ||
disabled={useZeroCount()} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,13 @@ | ||
import { | ||
useList, | ||
useTodo, | ||
delTodo, | ||
toggleTodo, | ||
updateTodo, | ||
addTodo, | ||
clearCompleted, | ||
filters, | ||
setFilter, | ||
toggleAll, | ||
useCount, | ||
useToggleAll, | ||
} from "./store"; | ||
import Actions from "./Actions"; | ||
import Title from "./Title"; | ||
import TodoList from "./TodoList"; | ||
|
||
export default function TodoApp() { | ||
return ( | ||
<div> | ||
<h3>Todo App ({useCount(false)} todos left)</h3> | ||
<div className="flex gap-1"> | ||
<ToggleAll /> | ||
<Filter /> | ||
<button onClick={addTodo} title="Add new todo"> | ||
+ | ||
</button> | ||
<button | ||
onClick={clearCompleted} | ||
disabled={useCount(true) === 0} | ||
title="Delete all completed todos" | ||
> | ||
✂️ | ||
</button> | ||
</div> | ||
|
||
<TodoList /> | ||
</div> | ||
); | ||
} | ||
|
||
// The component to toggle all todos. | ||
function ToggleAll() { | ||
return ( | ||
<input | ||
type="checkbox" | ||
checked={useToggleAll()} | ||
onChange={toggleAll} | ||
disabled={useList().length === 0} | ||
/> | ||
); | ||
} | ||
|
||
// The component to filter the todos. | ||
function Filter() { | ||
return ( | ||
<select onChange={(e) => setFilter(e.target.value)}> | ||
{filters.map((f) => ( | ||
<option key={f}>{f}</option> | ||
))} | ||
</select> | ||
); | ||
} | ||
|
||
// The component to display all filtered todos. | ||
function TodoList() { | ||
return ( | ||
<> | ||
{useList().map((id) => { | ||
return <TodoItem key={id} id={id} />; | ||
})} | ||
<Title /> | ||
<Actions /> | ||
<TodoList /> | ||
</> | ||
); | ||
} | ||
|
||
// The component to display a todo. | ||
function TodoItem({ id }: { id: number }) { | ||
const { done, text } = useTodo(id); | ||
|
||
return ( | ||
<div className="flex gap-1 my-1"> | ||
<input type="checkbox" checked={done} onChange={() => toggleTodo(id)} /> | ||
|
||
<input | ||
placeholder="Input text here" | ||
value={text} | ||
onChange={(e) => updateTodo(id, e.target.value)} | ||
disabled={done} | ||
autoFocus | ||
/> | ||
|
||
<button onClick={() => delTodo(id)} title="Delete current todo"> | ||
✕ | ||
</button> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.