diff --git a/src/App.jsx b/src/App.jsx index 5f3df15..95e1f50 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -115,6 +115,7 @@ export default function App() { const [loading, setLoading] = useState(false); const stopGenerationRef = useRef(false); const reactFlowWrapper = useRef(null); + const fileInputRef = useRef(null); const handleExport = () => { if (reactFlowWrapper.current) { @@ -126,6 +127,40 @@ export default function App() { } }; + const handleSave = () => { + const data = { + nodes, + edges, + }; + const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); + saveAs(blob, 'nodeverse-mindmap.json'); + }; + + const handleLoad = (event) => { + if (window.confirm('Loading a new file will replace your current work. Are you sure?')) { + const file = event.target.files[0]; + if (file && file.type === 'application/json') { + const reader = new FileReader(); + reader.onload = (e) => { + try { + const { nodes: loadedNodes, edges: loadedEdges } = JSON.parse(e.target.result); + if (loadedNodes && loadedEdges) { + setNodes(loadedNodes); + setEdges(loadedEdges); + } else { + alert('Invalid JSON file.'); + } + } catch (error) { + alert('Error loading file.'); + } + }; + reader.readAsText(file); + } else { + alert('Please select a JSON file.'); + } + } + }; + const handleSubmit = async () => { if (!prompt.trim()) return; setLoading(true); @@ -246,6 +281,45 @@ export default function App() { > Export as PNG + + +