00Boobs00 commited on
Commit
f5acd7a
·
verified ·
1 Parent(s): 5a5ece4

Upload components/ProjectContext.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/ProjectContext.js +45 -0
components/ProjectContext.js ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createContext, useContext, useState } from 'react'
2
+
3
+ const ProjectContext = createContext()
4
+
5
+ export function ProjectProvider({ children }) {
6
+ const [projects, setProjects] = useState([])
7
+
8
+ const saveProject = (name, nodes, connections) => {
9
+ const project = {
10
+ id: Date.now(),
11
+ name,
12
+ nodes,
13
+ connections,
14
+ createdAt: new Date().toISOString()
15
+ }
16
+ const updatedProjects = [...projects, project]
17
+ setProjects(updatedProjects)
18
+ localStorage.setItem('neuroarch-projects', JSON.stringify(updatedProjects))
19
+ }
20
+
21
+ const loadProject = (projectId) => {
22
+ const project = projects.find(p => p.id === projectId)
23
+ return project
24
+ }
25
+
26
+ const deleteProject = (projectId) => {
27
+ const updatedProjects = projects.filter(p => p.id !== projectId)
28
+ setProjects(updatedProjects)
29
+ localStorage.setItem('neuroarch-projects', JSON.stringify(updatedProjects))
30
+ }
31
+
32
+ return (
33
+ <ProjectContext.Provider value={{ projects, saveProject, loadProject, deleteProject }}>
34
+ {children}
35
+ </ProjectContext.Provider>
36
+ )
37
+ }
38
+
39
+ export function useProject() {
40
+ const context = useContext(ProjectContext)
41
+ if (!context) {
42
+ throw new Error('useProject must be used within ProjectProvider')
43
+ }
44
+ return context
45
+ }