mirror of
https://github.com/remvze/moodist.git
synced 2025-12-18 09:24: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() {
|
export function Todos() {
|
||||||
const todos = useTodoStore(state => state.todos);
|
const todos = useTodoStore(state => state.todos);
|
||||||
|
const doneCount = useTodoStore(state => state.doneCount());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.todos}>
|
<div className={styles.todos}>
|
||||||
<header>
|
<header>
|
||||||
<p className={styles.label}>Your Todos</p>
|
<p className={styles.label}>Your Todos</p>
|
||||||
<div className={styles.divider} />
|
<div className={styles.divider} />
|
||||||
<p className={styles.counter}>0 / 0</p>
|
<p className={styles.counter}>
|
||||||
|
{doneCount} / {todos.length}
|
||||||
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{todos.length > 0 ? (
|
{todos.length > 0 ? (
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { v4 as uuid } from 'uuid';
|
||||||
interface TodoStore {
|
interface TodoStore {
|
||||||
addTodo: (todo: string) => void;
|
addTodo: (todo: string) => void;
|
||||||
deleteTodo: (id: string) => void;
|
deleteTodo: (id: string) => void;
|
||||||
|
doneCount: () => number;
|
||||||
editTodo: (id: string, newTodo: string) => void;
|
editTodo: (id: string, newTodo: string) => void;
|
||||||
todos: Array<{
|
todos: Array<{
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
|
|
@ -32,13 +33,18 @@ export const useTodoStore = create<TodoStore>()(
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteTodo(id) {
|
deleteTodo(id) {
|
||||||
set({
|
set({
|
||||||
todos: get().todos.filter(todo => todo.id !== id),
|
todos: get().todos.filter(todo => todo.id !== id),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
doneCount() {
|
||||||
|
const { todos } = get();
|
||||||
|
|
||||||
|
return todos.filter(todo => todo.done).length;
|
||||||
|
},
|
||||||
|
|
||||||
editTodo(id, newTodo) {
|
editTodo(id, newTodo) {
|
||||||
set({
|
set({
|
||||||
todos: get().todos.map(todo => {
|
todos: get().todos.map(todo => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue