9d06226cb4
and centralized backend requests via api/apiFetch (including data provider updates) to inject X-Project-ID.
28 lines
673 B
TypeScript
28 lines
673 B
TypeScript
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 });
|
|
},
|
|
}));
|