Skip to content

Commit ae7b7a4

Browse files
committed
fix flow diagram nodes issues
1 parent 1e54786 commit ae7b7a4

File tree

2 files changed

+63
-68
lines changed

2 files changed

+63
-68
lines changed

apps/web/src/app/(home)/_components/CustomizableStack.tsx

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import {
44
Background,
5-
type Connection,
6-
type Edge,
75
ReactFlow,
86
useEdgesState,
97
useNodesState,
@@ -66,76 +64,73 @@ const CustomizableStack = () => {
6664
},
6765
})),
6866
);
69-
70-
const sourceNodes = nodes.filter(
71-
(n) => n.data.isActive && !n.data.isStatic,
72-
);
73-
const targetNode = nodes.find((n) => n.id === techId);
74-
75-
if (!targetNode) return;
76-
7767
setEdges((eds) =>
78-
eds.filter(
79-
(edge) =>
80-
!nodes.some(
81-
(n) =>
82-
n.data.category === category &&
83-
(edge.source === n.id || edge.target === n.id),
84-
),
85-
),
68+
eds.filter((edge) => {
69+
const targetNode = nodes.find((n) => n.id === edge.target);
70+
const sourceNode = nodes.find((n) => n.id === edge.source);
71+
return !(
72+
targetNode?.data.category === category ||
73+
sourceNode?.data.category === category
74+
);
75+
}),
8676
);
8777

88-
setEdges((eds) => [
89-
...eds,
90-
...sourceNodes.map((source) => ({
91-
id: `${source.id}-${techId}`,
92-
source: source.id,
93-
target: techId,
94-
animated: true,
95-
})),
96-
]);
78+
if (category === "database") {
79+
const honoNode = nodes.find((n) => n.id === "hono");
80+
const ormNode = nodes.find(
81+
(n) => n.data.category === "orm" && n.data.isActive,
82+
);
83+
84+
if (honoNode && ormNode) {
85+
setEdges((eds) => [
86+
...eds,
87+
{
88+
id: `hono-${techId}`,
89+
source: "hono",
90+
target: techId,
91+
animated: true,
92+
},
93+
{
94+
id: `${techId}-${ormNode.id}`,
95+
source: techId,
96+
target: ormNode.id,
97+
animated: true,
98+
},
99+
]);
100+
}
101+
} else if (category === "auth") {
102+
setEdges((eds) => [
103+
...eds,
104+
{
105+
id: `hono-${techId}`,
106+
source: "hono",
107+
target: techId,
108+
animated: true,
109+
},
110+
]);
111+
} else if (category === "orm") {
112+
const dbNode = nodes.find(
113+
(n) => n.data.category === "database" && n.data.isActive,
114+
);
115+
if (dbNode) {
116+
setEdges((eds) => [
117+
...eds,
118+
{
119+
id: `${dbNode.id}-${techId}`,
120+
source: dbNode.id,
121+
target: techId,
122+
animated: true,
123+
},
124+
]);
125+
}
126+
}
97127
},
98128
[nodes, setNodes, setEdges],
99129
);
100130

101-
const onConnect = useCallback(
102-
(connection: Connection) => {
103-
const sourceNode = nodes.find((n) => n.id === connection.source);
104-
const targetNode = nodes.find((n) => n.id === connection.target);
105-
106-
if (!sourceNode || !targetNode) return;
107-
108-
if (sourceNode.data.group === targetNode.data.group) {
109-
return;
110-
}
111-
112-
const edgesToRemove = edges.filter((edge) => {
113-
const edgeTarget = nodes.find((n) => n.id === edge.target);
114-
return edgeTarget?.data.group === targetNode.data.group;
115-
});
116-
117-
setEdges((eds) => {
118-
const newEdges = eds.filter((edge) => !edgesToRemove.includes(edge));
119-
return [...newEdges, { ...(connection as Edge), animated: true }];
120-
});
121-
122-
setNodes((nds) =>
123-
nds.map((node) => ({
124-
...node,
125-
data: {
126-
...node.data,
127-
isActive:
128-
node.id === connection.source || node.id === connection.target
129-
? true
130-
: node.data.group !== targetNode.data.group
131-
? node.data.isActive
132-
: false,
133-
},
134-
})),
135-
);
136-
},
137-
[nodes, edges, setEdges, setNodes],
138-
);
131+
const onConnect = useCallback(() => {
132+
return;
133+
}, []);
139134

140135
const generateCommand = useCallback(() => {
141136
const flags: string[] = ["-y"];

apps/web/src/lib/constant.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const technologies = [
9494
description: "TypeScript ORM",
9595
},
9696
{
97-
name: "libSQL",
97+
name: "Sqlite",
9898
category: "backend",
9999
angle: -30,
100100
icon: Boxes,
@@ -171,11 +171,11 @@ export const initialNodes: TechNode[] = [
171171
},
172172
},
173173
{
174-
id: "libsql",
174+
id: "sqlite",
175175
type: "techNode",
176176
position: { x: 544, y: 532 },
177177
data: {
178-
label: "libSQL",
178+
label: "Sqlite",
179179
category: "database",
180180
description: "SQLite-compatible database",
181181
isDefault: true,

0 commit comments

Comments
 (0)