import { useSuspenseQuery } from '@tanstack/react-query' import { createFileRoute } from '@tanstack/react-router' import { createServerFn } from '@tanstack/react-start' import { db } from '@/db' const getTodos = createServerFn({ method: 'GET' }).handler(async () => { const todos = await db.query.todoTable.findMany() return todos }) export const Route = createFileRoute('/todo')({ component: Todo, }) function Todo() { const { data: todos } = useSuspenseQuery({ queryKey: ['todos'], queryFn: () => getTodos(), }) const completedCount = todos.filter((todo) => todo.completed).length const totalCount = todos.length return (
{/* Header */}

我的待办事项

已完成 {completedCount} / {totalCount} 项任务

{/* Progress Bar */}
完成进度 {totalCount > 0 ? Math.round((completedCount / totalCount) * 100) : 0} %
0 ? (completedCount / totalCount) * 100 : 0}%`, }} />
{/* Todo List */}
{todos.length === 0 ? (

暂无待办事项

添加你的第一个任务开始吧!

) : ( todos.map((todo) => (
{/* Checkbox */}
{todo.completed && ( )}
{/* Todo Content */}

{todo.title}

{new Date(todo.createdAt).toLocaleDateString('zh-CN')}
{/* Status Badge */}
{todo.completed ? '已完成' : '进行中'}
)) )}
{/* Footer Stats */} {todos.length > 0 && (

{totalCount - completedCount}

待完成

{completedCount}

已完成

)}
) }