Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,35 @@
.read-the-docs {
color: #888;
}

/* 📍 Color Legend Styles */
.color-legend {
position: absolute;
top: 20px;
left: 20px;
background: rgba(34, 34, 34, 0.9);
padding: 12px;
border-radius: 10px;
border: 1px solid #444;
color: white;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 8px;
pointer-events: none;
}

.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.9rem;
font-weight: 500;
}

.dot {
width: 12px;
height: 12px;
border-radius: 50%;
display: inline-block;
}
75 changes: 62 additions & 13 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 📦 Imports
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useEffect } from 'react';
import ReactFlow, {
Background,
Controls,
Expand All @@ -8,14 +8,21 @@ import ReactFlow, {
applyNodeChanges,
} from 'reactflow';
import 'reactflow/dist/style.css';
import './App.css';
import axios from 'axios';
import html2canvas from 'html2canvas';
import { saveAs } from 'file-saver';

// 🧠 Initial State & Helpers
const initialNodes = [];
const initialEdges = [];
let nodeId = 1;
const initialNodes = JSON.parse(localStorage.getItem('nodes')) || [];
const initialEdges = JSON.parse(localStorage.getItem('edges')) || [];

const getMaxId = (nodes) => {
const ids = nodes.map((n) => parseInt(n.id)).filter((id) => !isNaN(id));
return ids.length > 0 ? Math.max(...ids) : 0;
};

let nodeId = getMaxId(initialNodes) + 1;

const getColor = (type) => {
switch (type) {
Expand All @@ -27,9 +34,9 @@ const getColor = (type) => {
};

// 🤖 AI Logic with Domino Effect Thinking (Updated: Using Puter AI API)
const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef) => {
const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef, parentPos, depth = 1) => {
try {
if (stopGenerationRef.current) return;
if (stopGenerationRef.current || depth < 0) return;
const res = await axios.post(
'https://api.puter.com/v1/chat/completions',
{
Expand Down Expand Up @@ -69,8 +76,8 @@ Return only 3 outputs: one of each type.`
id: newId,
data: { label: line.replace(/^\d+\.\s*/, '') },
position: {
x: 300 + Math.random() * 300,
y: 200 + Math.random() * 300
x: parentPos.x + 350,
y: parentPos.y + (idx - 1) * 150
},
style: {
background: getColor(childTypes[idx]),
Expand All @@ -94,9 +101,11 @@ Return only 3 outputs: one of each type.`
setEdges((eds) => [...eds, ...newEdges]);

// Recursively expand each child one level deep
for (const n of newNodes) {
if (stopGenerationRef.current) break;
await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef);
if (depth > 0) {
for (const n of newNodes) {
if (stopGenerationRef.current) break;
await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef, n.position, depth - 1);
}
}

} catch (err) {
Expand All @@ -112,6 +121,12 @@ export default function App() {
const [nodes, setNodes] = useState(initialNodes);
const [edges, setEdges] = useState(initialEdges);
const [prompt, setPrompt] = useState('');

// 💾 Persistence
useEffect(() => {
localStorage.setItem('nodes', JSON.stringify(nodes));
localStorage.setItem('edges', JSON.stringify(edges));
}, [nodes, edges]);
const [loading, setLoading] = useState(false);
const stopGenerationRef = useRef(false);
const reactFlowWrapper = useRef(null);
Expand Down Expand Up @@ -150,7 +165,7 @@ export default function App() {
setNodes([rootNode]);
setEdges([]);

await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef);
await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef, rootNode.position);

setPrompt('');
setLoading(false);
Expand All @@ -161,10 +176,21 @@ export default function App() {
setLoading(false);
};

const handleClearAll = () => {
if (window.confirm('Are you sure you want to clear the entire mind map?')) {
setNodes([]);
setEdges([]);
localStorage.removeItem('nodes');
localStorage.removeItem('edges');
// Reset nodeId for fresh start
nodeId = 1;
}
};

const onNodeClick = async (_event, node) => {
stopGenerationRef.current = false;
setLoading(true);
await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef);
await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef, node.position);
setLoading(false);
};

Expand Down Expand Up @@ -246,6 +272,22 @@ export default function App() {
>
Export as PNG
</button>
<button
onClick={handleClearAll}
disabled={loading || nodes.length === 0}
style={{
padding: '10px 20px',
backgroundColor: '#f44336',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: loading || nodes.length === 0 ? 'not-allowed' : 'pointer',
opacity: loading || nodes.length === 0 ? 0.7 : 1,
}}
>
Clear All
</button>
</div>
</div>

Expand All @@ -263,6 +305,13 @@ export default function App() {
<MiniMap style={{ backgroundColor: '#222' }} />
<Controls />
<Background variant="dots" gap={12} size={1} />
{/* 📍 Color Legend */}
<div className="color-legend">
<div className="legend-item"><span className="dot" style={{ background: '#6200ea' }}></span> Root</div>
<div className="legend-item"><span className="dot" style={{ background: '#00c853' }}></span> Positive</div>
<div className="legend-item"><span className="dot" style={{ background: '#ffd600' }}></span> Neutral</div>
<div className="legend-item"><span className="dot" style={{ background: '#d50000' }}></span> Negative</div>
</div>
</ReactFlow>
</div>
</div>
Expand Down