Implemented a Zustand-based project_id store, expanded project selection/switching to persist project_id,

and centralized backend requests via api/apiFetch (including data provider updates) to inject X-Project-ID.
This commit is contained in:
JIANG
2026-02-11 16:29:18 +08:00
parent a2e6c1f416
commit 9d06226cb4
25 changed files with 192 additions and 62 deletions
+27
View File
@@ -0,0 +1,27 @@
import { create } from "zustand";
interface ProjectState {
currentProjectId: string | null;
setCurrentProjectId: (id: string | null) => void;
}
const getInitialProjectId = () => {
if (typeof window === "undefined") {
return null;
}
return localStorage.getItem("active_project");
};
export const useProjectStore = create<ProjectState>((set) => ({
currentProjectId: getInitialProjectId(),
setCurrentProjectId: (id) => {
if (typeof window !== "undefined") {
if (id) {
localStorage.setItem("active_project", id);
} else {
localStorage.removeItem("active_project");
}
}
set({ currentProjectId: id });
},
}));