-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentContest.jsx
67 lines (60 loc) · 2.21 KB
/
ContentContest.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use client";
import React, { createContext, useContext, useMemo, useState } from 'react';
const ContentContext = createContext(undefined);
export const useContentContext = () => {
const context = useContext(ContentContext);
if (!context) {
throw new Error("useContentContext must be used within a ContentProvider");
}
return context;
};
export const ContentProvider = ({ children }) => {
const [organizations, setOrganizations] = useState([]);
const [models, setModels] = useState({});
const [nodes, setNodes] = useState([]);
const [selectedNoteId, setSelectedNoteId] = useState(null);
const [noteData, setNoteData] = useState({});
const [workflowId, setWorkflowId] = useState(null);
const [nodeId, setNodeId] = useState(null);
const [activeNodeId, setActiveNodeId] = useState(null);
const [workflows, setWorkflows] = useState([]);
const [selectedWorkflowId, setSelectedWorkflowId] = useState(null);
const contextValue = useMemo(() => ({
organizations, // Expose organizations state
setOrganizations, // Expose setOrganizations function
models, // Expose models state
setModels, // Expose setModels function
nodes, // Expose nodes state
setNodes, // Expose setNodes function
selectedNoteId, // Expose selectedNoteId state
setSelectedNoteId, // Expose setSelectedNoteId function
noteData, // Expose noteData state
setNoteData, // Expose setNoteData function
workflowId, // Expose workflowId state
setWorkflowId, // Expose setWorkflowId function
nodeId, // Expose nodeId state
setNodeId, // Expose setNodeId function
activeNodeId, // Expose activeNodeId state
setActiveNodeId,
workflows,
setWorkflows,
selectedWorkflowId,
setSelectedWorkflowId
}), [
organizations,
models,
nodes,
selectedNoteId,
noteData,
workflowId,
nodeId,
activeNodeId,
workflows,
selectedWorkflowId
]);
return (
<ContentContext.Provider value={contextValue}>
{children}
</ContentContext.Provider>
);
};