From 32d6604fe31e33e816c4e3abc500e62dac5fb812 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 14 Sep 2026 20:45:31 +0800 Subject: [PATCH] refactor: delete useMyTemplates.ts (#1899 #1900) --- .../my-templates/hooks/useMyTemplates.ts | 95 ------------------- 1 file changed, 95 deletions(-) delete mode 100644 apps/web/src/pages/my-templates/hooks/useMyTemplates.ts diff --git a/apps/web/src/pages/my-templates/hooks/useMyTemplates.ts b/apps/web/src/pages/my-templates/hooks/useMyTemplates.ts deleted file mode 100644 index 8823c8284..000000000 --- a/apps/web/src/pages/my-templates/hooks/useMyTemplates.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { useState } from "react" -import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query" -import { message } from "antd" -import { - getEditingTemplates, - getTemplateCategories, - deleteEditingTemplate, - createEditingTemplate, - type EditingTemplate, -} from "@/api/editing-planner" - -/** - * 我的模板数据 Hook - * 封装模板列表查询、筛选、删除、复制等数据操作 - */ -export function useMyTemplates() { - const queryClient = useQueryClient() - const [searchText, setSearchText] = useState("") - const [filterCategory, setFilterCategory] = useState("") - - /* 模板列表 */ - const { data: templates = [], isLoading } = useQuery({ - queryKey: ["editing-templates", filterCategory, searchText], - queryFn: () => - getEditingTemplates({ - category: filterCategory || undefined, - tag: searchText || undefined, - }), - }) - - /* 分类列表 */ - const { data: categories = [] } = useQuery({ - queryKey: ["template-categories"], - queryFn: getTemplateCategories, - }) - - /* 删除 mutation */ - const deleteMutation = useMutation({ - mutationFn: deleteEditingTemplate, - onSuccess: () => { - message.success("模板已删除") - queryClient.invalidateQueries({ queryKey: ["editing-templates"] }) - }, - onError: (err: unknown) => { - if (!(err as { __msgShown?: boolean })?.__msgShown) message.error("删除失败") - }, - }) - - /* 复制 mutation */ - const copyMutation = useMutation({ - mutationFn: (tpl: EditingTemplate) => - createEditingTemplate({ - name: `${tpl.name}(副本)`, - mode: tpl.mode, - category: tpl.category, - tags: tpl.tags, - title_config: tpl.title_config, - subtitle_config: tpl.subtitle_config, - bgm_config: tpl.bgm_config, - segments: tpl.segments.map(({ id: _id, ...rest }) => rest), - }), - onSuccess: () => { - message.success("模板已复制") - queryClient.invalidateQueries({ queryKey: ["editing-templates"] }) - }, - onError: (err: unknown) => { - if (!(err as { __msgShown?: boolean })?.__msgShown) message.error("复制失败") - }, - }) - - const handleCopy = (tpl: EditingTemplate) => { - copyMutation.mutate(tpl) - } - - const handleDelete = (id: string) => { - deleteMutation.mutate(id) - } - - return { - // 状态 - searchText, - setSearchText, - filterCategory, - setFilterCategory, - // 数据 - templates, - categories, - isLoading, - // 操作 - handleCopy, - handleDelete, - isDeleting: deleteMutation.isPending, - isCopying: copyMutation.isPending, - } -}