feat: Implement core application structure with new dashboard, settings, and help pages, and enhance opportunities management with persistence and filtering.
This commit is contained in:
46
components/project-context.tsx
Normal file
46
components/project-context.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||
|
||||
const STORAGE_KEY = "selectedProjectId";
|
||||
|
||||
type ProjectContextValue = {
|
||||
selectedProjectId: string | null;
|
||||
setSelectedProjectId: (id: string | null) => void;
|
||||
};
|
||||
|
||||
const ProjectContext = createContext<ProjectContextValue | null>(null);
|
||||
|
||||
export function ProjectProvider({ children }: { children: React.ReactNode }) {
|
||||
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const stored = window.localStorage.getItem(STORAGE_KEY);
|
||||
if (stored) {
|
||||
setSelectedProjectId(stored);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedProjectId) {
|
||||
window.localStorage.setItem(STORAGE_KEY, selectedProjectId);
|
||||
} else {
|
||||
window.localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
}, [selectedProjectId]);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({ selectedProjectId, setSelectedProjectId }),
|
||||
[selectedProjectId]
|
||||
);
|
||||
|
||||
return <ProjectContext.Provider value={value}>{children}</ProjectContext.Provider>;
|
||||
}
|
||||
|
||||
export function useProject() {
|
||||
const context = useContext(ProjectContext);
|
||||
if (!context) {
|
||||
throw new Error("useProject must be used within a ProjectProvider.");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user