Download components/ProjectContext.js from 00Boobs00/bolt-new: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/00Boobs00/bolt-new/resolve/main/components/ProjectContext.js
- Command line
-
hf download hf://spaces/00Boobs00/bolt-new/components/ProjectContext.js
-
curl -L -o ProjectContext.js https://huggingface.co/spaces/00Boobs00/bolt-new/resolve/main/components/ProjectContext.js
1.25 kB
| import { createContext, useContext, useState } from 'react' | |
| const ProjectContext = createContext() | |
| export function ProjectProvider({ children }) { | |
| const [projects, setProjects] = useState([]) | |
| const saveProject = (name, nodes, connections) => { | |
| const project = { | |
| id: Date.now(), | |
| name, | |
| nodes, | |
| connections, | |
| createdAt: new Date().toISOString() | |
| } | |
| const updatedProjects = [...projects, project] | |
| setProjects(updatedProjects) | |
| localStorage.setItem('neuroarch-projects', JSON.stringify(updatedProjects)) | |
| } | |
| const loadProject = (projectId) => { | |
| const project = projects.find(p => p.id === projectId) | |
| return project | |
| } | |
| const deleteProject = (projectId) => { | |
| const updatedProjects = projects.filter(p => p.id !== projectId) | |
| setProjects(updatedProjects) | |
| localStorage.setItem('neuroarch-projects', JSON.stringify(updatedProjects)) | |
| } | |
| return ( | |
| <ProjectContext.Provider value={{ projects, saveProject, loadProject, deleteProject }}> | |
| {children} | |
| </ProjectContext.Provider> | |
| ) | |
| } | |
| export function useProject() { | |
| const context = useContext(ProjectContext) | |
| if (!context) { | |
| throw new Error('useProject must be used within ProjectProvider') | |
| } | |
| return context | |
| } |