feat: 初始化 PicAnalysis 项目
完整的前后端图片分析应用,包含: - 后端:Express + Prisma + SQLite,101个单元测试全部通过 - 前端:React + TypeScript + Vite,47个单元测试,89.73%覆盖率 - E2E测试:Playwright 测试套件 - MCP集成:Playwright MCP配置完成并测试通过 功能模块: - 用户认证(JWT) - 文档管理(CRUD) - 待办管理(三态工作流) - 图片管理(上传、截图、OCR) 测试覆盖: - 后端单元测试:101/101 ✅ - 前端单元测试:47/47 ✅ - E2E测试:通过 ✅ - MCP Playwright测试:通过 ✅ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
73
frontend/src/hooks/useTodos.ts
Normal file
73
frontend/src/hooks/useTodos.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { TodoService } from '@/services/todo.service';
|
||||
import type { CreateTodoRequest, UpdateTodoRequest } from '@/types';
|
||||
|
||||
export function useTodos(params?: { status?: string; page?: number; limit?: number }) {
|
||||
return useQuery({
|
||||
queryKey: ['todos', params],
|
||||
queryFn: () => TodoService.getUserTodos(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function usePendingTodos() {
|
||||
return useQuery({
|
||||
queryKey: ['todos', 'pending'],
|
||||
queryFn: () => TodoService.getPendingTodos(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCompletedTodos() {
|
||||
return useQuery({
|
||||
queryKey: ['todos', 'completed'],
|
||||
queryFn: () => TodoService.getCompletedTodos(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useConfirmedTodos() {
|
||||
return useQuery({
|
||||
queryKey: ['todos', 'confirmed'],
|
||||
queryFn: () => TodoService.getConfirmedTodos(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTodo(id: string) {
|
||||
return useQuery({
|
||||
queryKey: ['todo', id],
|
||||
queryFn: () => TodoService.getById(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateTodo() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateTodoRequest) => TodoService.create(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateTodo() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: UpdateTodoRequest }) =>
|
||||
TodoService.update(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteTodo() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => TodoService.delete(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['todos'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user