From 6a2f2e1b0081335f245f085d8a344ad21449614b Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sun, 18 Jan 2026 01:44:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=BE=85=E5=8A=9E?= =?UTF-8?q?=E4=BA=8B=E9=A1=B9=E6=93=8D=E4=BD=9C=E5=B9=B6=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新待办事项创建、切换和删除操作,确保在成功后重新获取数据并重置输入状态。 --- src/routes/todos.tsx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/routes/todos.tsx b/src/routes/todos.tsx index 1dcefac..4ad16f1 100644 --- a/src/routes/todos.tsx +++ b/src/routes/todos.tsx @@ -19,7 +19,15 @@ function Todo() { const handleCreateTodo = (e: FormEvent) => { e.preventDefault() if (newTodoTitle.trim()) { - createMutation.mutate(newTodoTitle.trim()) + createMutation.mutate( + { title: newTodoTitle.trim() }, + { + onSuccess: () => { + setNewTodoTitle('') + listQuery.refetch() + }, + }, + ) } } @@ -28,13 +36,31 @@ function Todo() { } const handleToggleTodo = (id: string, currentCompleted: boolean) => { - updateMutation.mutate({ id, completed: !currentCompleted }) + updateMutation.mutate( + { + id, + data: { completed: !currentCompleted }, + }, + { + onSuccess: () => { + listQuery.refetch() + }, + }, + ) } const handleDeleteTodo = (id: string) => { - deleteMutation.mutate(id) + deleteMutation.mutate( + { id }, + { + onSuccess: () => { + listQuery.refetch() + }, + }, + ) } + const todos = listQuery.data const completedCount = todos.filter((todo) => todo.completed).length const totalCount = todos.length const progress = totalCount > 0 ? (completedCount / totalCount) * 100 : 0