mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 00:44:14 +00:00
feat: add done counter
This commit is contained in:
parent
c6cc61a17f
commit
aa8161aac5
2 changed files with 11 additions and 2 deletions
|
|
@ -6,13 +6,16 @@ import styles from './todos.module.css';
|
|||
|
||||
export function Todos() {
|
||||
const todos = useTodoStore(state => state.todos);
|
||||
const doneCount = useTodoStore(state => state.doneCount());
|
||||
|
||||
return (
|
||||
<div className={styles.todos}>
|
||||
<header>
|
||||
<p className={styles.label}>Your Todos</p>
|
||||
<div className={styles.divider} />
|
||||
<p className={styles.counter}>0 / 0</p>
|
||||
<p className={styles.counter}>
|
||||
{doneCount} / {todos.length}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{todos.length > 0 ? (
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { v4 as uuid } from 'uuid';
|
|||
interface TodoStore {
|
||||
addTodo: (todo: string) => void;
|
||||
deleteTodo: (id: string) => void;
|
||||
doneCount: () => number;
|
||||
editTodo: (id: string, newTodo: string) => void;
|
||||
todos: Array<{
|
||||
createdAt: number;
|
||||
|
|
@ -32,13 +33,18 @@ export const useTodoStore = create<TodoStore>()(
|
|||
],
|
||||
});
|
||||
},
|
||||
|
||||
deleteTodo(id) {
|
||||
set({
|
||||
todos: get().todos.filter(todo => todo.id !== id),
|
||||
});
|
||||
},
|
||||
|
||||
doneCount() {
|
||||
const { todos } = get();
|
||||
|
||||
return todos.filter(todo => todo.done).length;
|
||||
},
|
||||
|
||||
editTodo(id, newTodo) {
|
||||
set({
|
||||
todos: get().todos.map(todo => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue