-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPanel.js
61 lines (51 loc) · 1.98 KB
/
Panel.js
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
// Panel.js
import React from 'react';
import { saveJson, loadJson } from './JsonUtils';
import RunWindow from './RunWindow';
import FileTransmit from './FileTransmit';
import ConfigWindow from '../ConfigWindow';
import { useGraphManager } from './GraphManager';
function Panel({ showConfig, setShowConfig, showRun, setShowRun}) {
const {
nodes,
setNodes,
edges,
setEdges,
nodeIdCounter,
setNodeIdCounter,
} = useGraphManager();
const handleNew = () => {
setNodes([]);
setEdges([]);
setNodeIdCounter(1);
};
const handleSave = async () => {
await saveJson(nodes, nodeIdCounter);
};
const handleLoad = async () => {
handleNew();
await loadJson(setEdges, setNodes, setNodeIdCounter);
};
const handleRun = () => {
setShowRun(true);
};
const handleConfig = () => {
setShowConfig(true);
};
const handleUploadComplete = () => {
console.log('Upload complete.');
};
return (
<nav className="p-2 border-b border-gray-300 mb-2 bg-white z-20">
<button className="mr-2 bg-blue-500 hover:bg-blue-700 text-white font-bold px-2 rounded" onClick={handleNew}>New Graph</button>
<button className="mr-2 bg-blue-500 hover:bg-blue-700 text-white font-bold px-2 rounded" onClick={handleSave}>Save Graph</button>
<button className="mr-2 bg-blue-500 hover:bg-blue-700 text-white font-bold px-2 rounded" onClick={handleLoad}>Load Graph</button>
<button className="mr-2 bg-blue-500 hover:bg-blue-700 text-white font-bold px-2 rounded" onClick={handleRun}>Run Graph</button>
<button className="mr-2 bg-blue-500 hover:bg-blue-700 text-white font-bold px-2 rounded" onClick={handleConfig}>Config</button>
<FileTransmit onUploadComplete={handleUploadComplete} />
{showConfig && <ConfigWindow onClose={() => setShowConfig(false)} />}
{showRun && <RunWindow onClose={() => setShowRun(false)} />}
</nav>
);
}
export default Panel;