Skip to content

Commit cbd0756

Browse files
committed
feat: 노드 색상 설정 기능 구현
1 parent 2c717a1 commit cbd0756

File tree

6 files changed

+111
-1
lines changed

6 files changed

+111
-1
lines changed

apps/frontend/src/app/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useSyncedUsers } from "@/entities/user";
22
import { useGetUser } from "@/features/auth";
3-
import { CanvasToolsView } from "@/widgets/CanvasToolsView";
43
import { CanvasView } from "@/widgets/CanvasView";
4+
import { CanvasToolsView } from "@/widgets/CanvasToolsView";
55
import { EditorView } from "@/widgets/EditorView";
6+
import { NodeToolsView } from "@/widgets/NodeToolsView";
67
import { PageSideBarView } from "@/widgets/PageSideBarView";
78
import { SideWrapper } from "@/shared/ui";
89

@@ -22,6 +23,7 @@ function App() {
2223
>
2324
<PageSideBarView />
2425
<CanvasToolsView />
26+
<NodeToolsView />
2527
</SideWrapper>
2628
</div>
2729
);

apps/frontend/src/entities/node/ui/NoteNode/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function NoteNode({
2020
return (
2121
<div
2222
className={`h-24 w-48 rounded-lg border-[1px] ${isClicked ? "border-[#8dbaef]" : "border-[#eaeaea]"} bg-white p-3 shadow-sm`}
23+
style={{ backgroundColor: data.color }}
2324
onClick={handleNodeClick}
2425
>
2526
<Handle
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { usePopover } from "@/shared/model";
2+
3+
interface NodeFormProps {
4+
changeNodeColor: (color: string) => void;
5+
}
6+
7+
export function NodeForm({ changeNodeColor }: NodeFormProps) {
8+
const { close } = usePopover();
9+
10+
const nodeBackgroundColors = {
11+
white: "#FFFFFF",
12+
grey: "#F1F1EF",
13+
brown: "#F4EEEE",
14+
orange: "#FBEBDD",
15+
yellow: "#FCF3DB",
16+
green: "#EDF3ED",
17+
blue: "#E7F3F8",
18+
purple: "#F7F3F8",
19+
pink: "#FBF2F5",
20+
red: "#FDEBEC",
21+
};
22+
23+
const handleButtonClick = (color: string) => {
24+
changeNodeColor(color);
25+
close();
26+
};
27+
28+
return (
29+
<div className="flex flex-col gap-2">
30+
<p className="text-sm text-neutral-500">Background color</p>
31+
<div className="grid grid-cols-5 gap-4">
32+
{Object.entries(nodeBackgroundColors).map(([key, color]) => {
33+
return (
34+
<button
35+
key={key}
36+
onClick={() => handleButtonClick(color)}
37+
className="h-7 w-7 rounded-md border-[1px] border-neutral-300 hover:cursor-pointer"
38+
style={{ backgroundColor: color }}
39+
/>
40+
);
41+
})}
42+
</div>
43+
</div>
44+
);
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { useEffect, useState } from "react";
2+
3+
import { NodeForm } from "../NodeForm";
4+
import { Node } from "@/entities/node";
5+
import { useYDocStore } from "@/shared/model";
6+
import { Popover } from "@/shared/ui";
7+
8+
interface NodePanelProps {
9+
currentPage: string;
10+
}
11+
12+
export function NodePanel({ currentPage }: NodePanelProps) {
13+
const [currentColor, setCurrentColor] = useState("#ffffff");
14+
const { ydoc } = useYDocStore();
15+
16+
const changeNodeColor = (color: string) => {
17+
const nodesMap = ydoc.getMap("nodes");
18+
const id = currentPage.toString();
19+
20+
const existingNode = nodesMap.get(id) as Node;
21+
nodesMap.set(id, {
22+
...existingNode,
23+
data: { ...existingNode.data, color },
24+
});
25+
setCurrentColor(color);
26+
};
27+
28+
useEffect(() => {
29+
const nodesMap = ydoc.getMap("nodes");
30+
const currentNode = nodesMap.get(currentPage.toString()) as Node;
31+
setCurrentColor(currentNode.data.color as string);
32+
}, [currentPage]);
33+
34+
return (
35+
<Popover placement="bottom" align="start" offset={{ x: -11, y: 16 }}>
36+
<Popover.Trigger>
37+
<button
38+
className="flex h-7 w-7 items-center justify-center rounded-md border-[1px] border-neutral-300"
39+
style={{ backgroundColor: currentColor }}
40+
/>
41+
</Popover.Trigger>
42+
<Popover.Content className="rounded-lg border bg-white p-3 shadow-md">
43+
<NodeForm changeNodeColor={changeNodeColor} />
44+
</Popover.Content>
45+
</Popover>
46+
);
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { NodeToolsView } from "./ui";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { usePageStore } from "@/entities/page";
2+
import { NodePanel } from "@/features/canvasTools/ui/NodePanel";
3+
4+
export function NodeToolsView() {
5+
const { currentPage } = usePageStore();
6+
7+
if (!currentPage) return null;
8+
9+
return (
10+
<div className="z-10 flex flex-row rounded-xl border-[1px] border-neutral-200 bg-white p-2.5 text-black shadow-md">
11+
<NodePanel currentPage={currentPage.toString()} />
12+
</div>
13+
);
14+
}

0 commit comments

Comments
 (0)