Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -246,6 +281,45 @@ export default function App() {
>
Export as PNG
</button>
<button
onClick={handleSave}
disabled={loading || nodes.length === 0}
style={{
padding: '10px 20px',
backgroundColor: '#2196F3',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: loading || nodes.length === 0 ? 'not-allowed' : 'pointer',
opacity: loading || nodes.length === 0 ? 0.7 : 1,
}}
>
Save
</button>
<input
type="file"
ref={fileInputRef}
style={{ display: 'none' }}
onChange={handleLoad}
accept=".json"
/>
<button
onClick={() => fileInputRef.current.click()}
disabled={loading}
style={{
padding: '10px 20px',
backgroundColor: '#FF9800',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: loading ? 'not-allowed' : 'pointer',
opacity: loading ? 0.7 : 1,
}}
>
Load
</button>
</div>
</div>

Expand Down