Skip to content

Commit 65d2b93

Browse files
committed
merge textnode and shapenode, add sidebar, fix style bar
1 parent 72b63b6 commit 65d2b93

File tree

17 files changed

+568
-367
lines changed

17 files changed

+568
-367
lines changed

client/src/app/globals.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@import "tailwindcss";
2-
32
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&family=Chewy&display=swap');
43

54
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');

client/src/app/page.tsx

Lines changed: 3 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,7 @@
11
"use client";
2-
import React from "react";
3-
import {
4-
ReactFlow,
5-
Background,
6-
BackgroundVariant,
7-
Controls,
8-
Edge,
9-
Node,
10-
} from "@xyflow/react";
11-
import "@xyflow/react/dist/style.css";
12-
import ShapeNode from "@/components/shape-node/ShapeNode";
13-
import Circle from "@/assets/shapes/circle.svg";
14-
import Rectangle from "@/assets/shapes/rectangle.svg";
15-
import Trapezoid from "@/assets/shapes/trapezoid.svg";
16-
import Diamond from "@/assets/shapes/diamond.svg";
17-
import Hexagon from "@/assets/shapes/hexagon.svg";
18-
import Parallelogram from "@/assets/shapes/parallelogram.svg";
19-
import Triangle from "@/assets/shapes/triangle.svg";
20-
import { defaultShapeNodeProperties } from "@/types/ShapeNodeProperties";
212

22-
export default function Home() {
23-
const nodeTypes = {
24-
ShapeNode,
25-
};
26-
27-
const initialNodes: Node[] = [
28-
{
29-
id: "2",
30-
type: "ShapeNode",
31-
data: {
32-
label: "circle",
33-
Shape: Circle,
34-
nodeProperties: defaultShapeNodeProperties,
35-
},
36-
position: { x: 0, y: 50 },
37-
},
38-
39-
{
40-
id: "1",
41-
type: "ShapeNode",
42-
data: {
43-
label: "rectangle",
44-
Shape: Rectangle,
45-
nodeProperties: defaultShapeNodeProperties,
46-
},
47-
position: { x: 0, y: 300 },
48-
},
49-
50-
{
51-
id: "3",
52-
type: "ShapeNode",
53-
data: {
54-
label: "trapezoid",
55-
Shape: Trapezoid,
56-
nodeProperties: defaultShapeNodeProperties,
57-
},
58-
position: { x: 300, y: 50 },
59-
},
60-
61-
{
62-
id: "4",
63-
type: "ShapeNode",
64-
data: {
65-
label: "diamond",
66-
Shape: Diamond,
67-
nodeProperties: defaultShapeNodeProperties,
68-
},
69-
position: { x: 300, y: 300 },
70-
},
3+
import WhiteBoard from "@/components/WhiteBoard";
714

72-
{
73-
id: "5",
74-
type: "ShapeNode",
75-
data: {
76-
label: "hexagon",
77-
Shape: Hexagon,
78-
nodeProperties: defaultShapeNodeProperties,
79-
},
80-
position: { x: 600, y: 50 },
81-
},
82-
83-
{
84-
id: "6",
85-
type: "ShapeNode",
86-
data: {
87-
label: "parallelogram",
88-
Shape: Parallelogram,
89-
nodeProperties: defaultShapeNodeProperties,
90-
},
91-
position: { x: 600, y: 300 },
92-
},
93-
{
94-
id: "7",
95-
type: "ShapeNode",
96-
data: {
97-
label: "triangle",
98-
Shape: Triangle,
99-
nodeProperties: defaultShapeNodeProperties,
100-
},
101-
position: { x: 900, y: 150 },
102-
},
103-
];
104-
105-
const initialEdges: Edge[] = [];
106-
107-
return (
108-
<div style={{ width: "100vw", height: "100vh" }}>
109-
<ReactFlow
110-
defaultNodes={initialNodes}
111-
defaultEdges={initialEdges}
112-
minZoom={0.2}
113-
maxZoom={4}
114-
fitView
115-
nodeTypes={nodeTypes}
116-
fitViewOptions={{ padding: 0.5 }}
117-
>
118-
<Background variant={BackgroundVariant.Dots} />
119-
<Controls />
120-
</ReactFlow>
121-
</div>
122-
);
5+
export default function Home() {
6+
return <WhiteBoard />;
1237
}

client/src/components/TextNode.tsx

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,53 @@
1-
"use client";
2-
31
import React, { useCallback } from "react";
42
import {
53
ReactFlow,
6-
Background,
7-
BackgroundVariant,
8-
Controls,
94
Node,
5+
addEdge,
6+
Connection,
107
useNodesState,
8+
useEdgesState,
9+
Controls,
10+
Background,
11+
BackgroundVariant,
1112
} from "@xyflow/react";
12-
import { Button } from "@/components/ui/button";
13-
import { Type } from "lucide-react";
1413
import "@xyflow/react/dist/style.css";
15-
import { TextNode} from "@/components/TextNode";
14+
import Sidebar from "@/components/sidebar/Sidebar";
15+
import TextNode from "@/components/text-node/TextNode";
16+
import ShapeNode from "@/components/shape-node/ShapeNode";
1617

1718
const nodeTypes = {
1819
text: TextNode,
20+
shapeNode: ShapeNode,
1921
};
2022

21-
export function WhiteBoard() {
23+
export default function WhiteBoard() {
2224
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);
2325

24-
const onAddTextNode = useCallback(() => {
25-
const newNode: Node = {
26-
id: `text-${nodes.length + 1}`,
27-
type: 'text',
28-
position: { x: 100, y: 100 },
29-
data: {
30-
label: 'Add your text here',
31-
style: {
32-
fontWeight: 'normal',
33-
fontStyle: 'normal',
34-
textDecoration: 'none',
35-
color: '#000000'
36-
}
37-
},
38-
};
39-
setNodes((nds) => [...nds, newNode]);
40-
}, [nodes, setNodes]);
26+
const handleAddNode = useCallback(
27+
(newNode: Node) => {
28+
setNodes((nds) => [...nds, newNode]);
29+
},
30+
[setNodes],
31+
);
32+
33+
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
34+
35+
const onConnect = useCallback(
36+
(params: Connection) => setEdges((eds) => addEdge(params, eds)),
37+
[setEdges],
38+
);
4139

4240
return (
4341
<div style={{ width: "100vw", height: "100vh" }}>
44-
<div className="fixed left-4 top-1/2 -translate-y-1/2 z-10 flex flex-col gap-2 bg-white/50 backdrop-blur-sm p-3 rounded-xl shadow-lg border border-gray-200/50 w-40 h-[200px] items-center justify-center">
45-
<Button
46-
variant="ghost"
47-
size="icon"
48-
onClick={onAddTextNode}
49-
className="hover:bg-slate-100 w-8 h-8 rounded-lg"
50-
>
51-
<Type className="size-10"/>
52-
</Button>
42+
<div className="fixed left-4 top-1/2 -translate-y-1/2 z-10 ">
43+
<Sidebar onAddNode={handleAddNode} />
5344
</div>
54-
5545
<ReactFlow
5646
nodes={nodes}
47+
edges={edges}
5748
onNodesChange={onNodesChange}
49+
onEdgesChange={onEdgesChange}
50+
onConnect={onConnect}
5851
nodeTypes={nodeTypes}
5952
fitView
6053
>
@@ -63,4 +56,4 @@ export function WhiteBoard() {
6356
</ReactFlow>
6457
</div>
6558
);
66-
}
59+
}

0 commit comments

Comments
 (0)