-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilder.tsx
More file actions
48 lines (44 loc) · 1.49 KB
/
builder.tsx
File metadata and controls
48 lines (44 loc) · 1.49 KB
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
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import Navbar from '../components/Navbar';
import Sidebar from '../components/Sidebar';
import FlowBuilder from '../components/FlowBuilder';
import { supabase } from '../utils/supabaseClient';
export default function Builder() {
const router = useRouter();
const remixId = typeof router.query.remix === 'string' ? router.query.remix : undefined;
// Pass initialNodes/edges to FlowBuilder if remix param exists
const [remixFlow, setRemixFlow] = React.useState<{ nodes: any[]; edges: any[] } | null>(null);
useEffect(() => {
async function loadRemix() {
if (remixId) {
const { data, error } = await supabase
.from('flows')
.select('data')
.eq('id', remixId)
.eq('is_public', true)
.single();
if (data && data.data) {
setRemixFlow({ nodes: data.data.nodes ?? [], edges: data.data.edges ?? [] });
}
}
}
loadRemix();
// Only load when remixId changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [remixId]);
return (
<div className="min-h-screen bg-gray-50 flex flex-col">
<Navbar />
<div className="flex flex-1">
<Sidebar />
<main className="flex-1 p-8">
<FlowBuilder
initialNodes={remixFlow ? remixFlow.nodes : undefined}
initialEdges={remixFlow ? remixFlow.edges : undefined}
/>
</main>
</div>
</div>
);
}