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:
@@ -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 });
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user