|
1 | | -import { useEffect } from "react"; |
2 | | - |
3 | | -import { useNodeFactoryContext } from "@utils/nodeFactory"; |
4 | | -import { useNodeSystemContext } from "@utils/nodeSystem"; |
5 | | -import { useNodeHistoryContext } from "@utils/nodeHistory"; |
6 | | -import { usePromptContext } from "@utils/prompt"; |
7 | | -import { usePalleteContext } from "@utils/pallete"; |
8 | | -import { useVariablesContext } from "@utils/variables"; |
9 | | -import { loadProject, saveProject } from "@utils/engineTools"; |
10 | | -import { |
11 | | - getBreadcrumb, |
12 | | - getWindowTools, |
13 | | - loadActiveProjectId, |
14 | | - updatePalleteRegistry, |
15 | | -} from "@utils/projectTools"; |
| 1 | +import { useAppDataContext } from "@utils/appData"; |
16 | 2 |
|
17 | 3 | import { AppWindow } from "@components/window/AppWindow"; |
18 | 4 | import { Canvas } from "@components/engine/Canvas"; |
19 | 5 | import { Prompt } from "@components/commons/Prompt"; |
20 | 6 |
|
21 | 7 | export default function App() { |
22 | | - const { newNode } = useNodeFactoryContext()!; |
23 | | - |
24 | | - const { |
25 | | - nodeSystem, |
26 | | - isEntry, |
27 | | - createEntry, |
28 | | - entries, |
29 | | - overrideNodeSystem, |
30 | | - removeNode, |
31 | | - } = useNodeSystemContext()!; |
32 | | - |
33 | | - const { |
34 | | - promptComponent, |
35 | | - promptState, |
36 | | - statesList, |
37 | | - customComponents, |
38 | | - overrideVariables, |
39 | | - } = useVariablesContext()!; |
40 | | - |
41 | 8 | const { |
42 | | - activeNode, |
43 | | - openNode, |
44 | | - closeNode, |
45 | | - nodeHistory, |
46 | | - } = useNodeHistoryContext()!; |
47 | | - |
48 | | - const { |
49 | | - addSuggestion, |
| 9 | + windowTools, |
| 10 | + breadcrumb, |
50 | 11 | generateSuggestions, |
51 | | - } = usePalleteContext()!; |
52 | | - |
53 | | - const { |
54 | | - requestPrompt, |
55 | | - } = usePromptContext()!; |
56 | | - |
57 | | - const windowTools = getWindowTools( |
58 | | - closeNode, |
59 | | - isEntry, |
60 | | - activeNode, |
61 | | - overrideNodeSystem, |
62 | | - overrideVariables, |
63 | | - openNode, |
64 | | - removeNode, |
65 | | - nodeSystem, |
66 | | - entries, |
67 | | - statesList, |
68 | | - customComponents, |
69 | | - ); |
70 | | - |
71 | | - const windowExtraTitle = getBreadcrumb( |
72 | | - nodeHistory, |
73 | | - activeNode, |
74 | | - ); |
75 | | - |
76 | | - useEffect(() => { |
77 | | - (async () => { |
78 | | - const requireLoading = await loadActiveProjectId(); |
79 | | - if (!requireLoading) return; |
80 | | - |
81 | | - loadProject( |
82 | | - overrideNodeSystem, |
83 | | - overrideVariables, |
84 | | - openNode, |
85 | | - removeNode, |
86 | | - ) |
87 | | - })(); |
88 | | - }, [ |
89 | | - overrideNodeSystem, |
90 | | - overrideVariables, |
91 | | - openNode, |
92 | | - removeNode, |
93 | | - ]); |
94 | | - |
95 | | - useEffect(() => { |
96 | | - updatePalleteRegistry( |
97 | | - addSuggestion, |
98 | | - openNode, |
99 | | - entries, |
100 | | - createEntry, |
101 | | - requestPrompt, |
102 | | - promptComponent, |
103 | | - promptState, |
104 | | - ) |
105 | | - }, [ |
106 | | - addSuggestion, |
107 | | - openNode, |
108 | | - entries, |
109 | | - createEntry, |
110 | | - requestPrompt, |
111 | | - promptComponent, |
112 | | - promptState, |
113 | | - ]); |
114 | | - |
115 | | - useEffect(() => { |
116 | | - saveProject( |
117 | | - nodeSystem, |
118 | | - entries, |
119 | | - { |
120 | | - states: statesList, |
121 | | - customComponents, |
122 | | - }, |
123 | | - ); |
124 | | - }, [ |
125 | | - entries, |
126 | | - nodeSystem, |
127 | | - statesList, |
128 | | - customComponents, |
129 | | - ]); |
| 12 | + nodes, |
| 13 | + } = useAppDataContext()!; |
130 | 14 |
|
131 | 15 | return (<> |
132 | 16 | <AppWindow |
133 | 17 | tools={windowTools} |
134 | | - extraTitle={windowExtraTitle} |
| 18 | + breadcrumb={breadcrumb} |
135 | 19 | generateSuggestions={generateSuggestions} |
136 | 20 | > |
137 | | - <Canvas |
138 | | - nodes={[ |
139 | | - ...nodeSystem[activeNode]?.nodes || [], |
140 | | - newNode |
141 | | - ]} |
142 | | - /> |
| 21 | + <Canvas nodes={nodes} /> |
143 | 22 | <Prompt /> |
144 | 23 | </AppWindow> |
145 | 24 | </>); |
146 | 25 | } |
| 26 | + |
0 commit comments