fix(ai): 自动追加AI任务类型

This commit is contained in:
Script Generator
2026-07-02 18:01:38 +08:00
parent 04954356bb
commit a39dde3824
14 changed files with 241 additions and 78 deletions

View File

@@ -1,7 +1,7 @@
'use client';
import { create } from 'zustand';
import type { TaskCategory, CategoryGroup } from '@/lib/task-category';
import { PRESET_CATEGORIES, normalizeTaskCategories } from '@/lib/task-category';
import { PRESET_CATEGORIES, ensureTaskCategoryByName, normalizeTaskCategories } from '@/lib/task-category';
import { loadServerData, saveServerData } from '@/lib/server-data';
function saveStored(items: TaskCategory[]) {
@@ -19,6 +19,7 @@ interface TaskCategoryState {
categories: TaskCategory[];
fetchCategories: () => Promise<void>;
addCategory: (name: string, group: CategoryGroup, color?: string) => void;
ensureCategory: (name: string, group: CategoryGroup) => TaskCategory;
updateCategory: (id: string, data: Partial<TaskCategory>) => void;
deleteCategory: (id: string) => boolean;
}
@@ -47,6 +48,15 @@ export const useTaskCategoryStore = create<TaskCategoryState>((set, get) => ({
saveStored(updated);
},
ensureCategory: (name, group) => {
const result = ensureTaskCategoryByName(get().categories, name, group);
if (result.created) {
set({ categories: result.categories });
saveStored(result.categories);
}
return result.category;
},
updateCategory: (id, data) => {
const updated = get().categories.map((c) => (c.id === id ? { ...c, ...data } : c));
set({ categories: updated });