feat(frontend): Day 7 - frontend complete layout finished
This commit is contained in:
69
frontend/src/stores/useProjectStore.ts
Normal file
69
frontend/src/stores/useProjectStore.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
background: string;
|
||||
researchType: 'observational' | 'interventional';
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface ProjectState {
|
||||
// 当前选中的项目
|
||||
currentProject: Project | null;
|
||||
|
||||
// 所有项目列表
|
||||
projects: Project[];
|
||||
|
||||
// 是否显示创建项目对话框
|
||||
showCreateDialog: boolean;
|
||||
|
||||
// 是否显示编辑项目对话框
|
||||
showEditDialog: boolean;
|
||||
|
||||
// Actions
|
||||
setCurrentProject: (project: Project | null) => void;
|
||||
setProjects: (projects: Project[]) => void;
|
||||
addProject: (project: Project) => void;
|
||||
updateProject: (id: string, updates: Partial<Project>) => void;
|
||||
deleteProject: (id: string) => void;
|
||||
setShowCreateDialog: (show: boolean) => void;
|
||||
setShowEditDialog: (show: boolean) => void;
|
||||
}
|
||||
|
||||
export const useProjectStore = create<ProjectState>((set) => ({
|
||||
currentProject: null,
|
||||
projects: [],
|
||||
showCreateDialog: false,
|
||||
showEditDialog: false,
|
||||
|
||||
setCurrentProject: (project) => set({ currentProject: project }),
|
||||
|
||||
setProjects: (projects) => set({ projects }),
|
||||
|
||||
addProject: (project) => set((state) => ({
|
||||
projects: [...state.projects, project],
|
||||
})),
|
||||
|
||||
updateProject: (id, updates) => set((state) => ({
|
||||
projects: state.projects.map((p) =>
|
||||
p.id === id ? { ...p, ...updates } : p
|
||||
),
|
||||
currentProject:
|
||||
state.currentProject?.id === id
|
||||
? { ...state.currentProject, ...updates }
|
||||
: state.currentProject,
|
||||
})),
|
||||
|
||||
deleteProject: (id) => set((state) => ({
|
||||
projects: state.projects.filter((p) => p.id !== id),
|
||||
currentProject:
|
||||
state.currentProject?.id === id ? null : state.currentProject,
|
||||
})),
|
||||
|
||||
setShowCreateDialog: (show) => set({ showCreateDialog: show }),
|
||||
|
||||
setShowEditDialog: (show) => set({ showEditDialog: show }),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user