Skip to content

Commit 5049cef

Browse files
authored
Merge pull request #246 from boostcampwm-2024/feature-fe-#240
노드 컴포넌트, ActiveUser 컴포넌트 수정
2 parents 93cbfe8 + b8a117d commit 5049cef

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

apps/frontend/src/components/canvas/NoteNode.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import { Handle, NodeProps, Position, type Node } from "@xyflow/react";
2+
import { FileText } from "lucide-react";
23

34
import ActiveUser from "../commons/activeUser";
45

56
import usePageStore from "@/store/usePageStore";
67
import useUserStore from "@/store/useUserStore";
78
import Emoji from "../commons/emoji";
9+
import { useEffect, useState } from "react";
810

9-
export type NoteNodeData = { title: string; id: number; emoji: string };
11+
export type NoteNodeData = { title: string; id: number; emoji?: string };
1012
export type NoteNodeType = Node<NoteNodeData, "note">;
1113

1214
export function NoteNode({ data }: NodeProps<NoteNodeType>) {
1315
const { setCurrentPage } = usePageStore();
1416
const { users } = useUserStore();
1517

18+
const [activeUsers, setActiveUsers] = useState(users);
19+
20+
useEffect(() => {
21+
setActiveUsers(users);
22+
}, [users]);
23+
1624
const handleNodeClick = () => {
1725
const id = data.id;
1826
if (id === undefined || id === null) {
@@ -24,7 +32,7 @@ export function NoteNode({ data }: NodeProps<NoteNodeType>) {
2432

2533
return (
2634
<div
27-
className="rounded-md border-[1px] border-black bg-neutral-100 p-2"
35+
className="h-24 w-48 rounded-lg border-[1px] border-[#eaeaea] bg-white p-3 shadow-sm"
2836
onClick={handleNodeClick}
2937
>
3038
<Handle
@@ -51,16 +59,26 @@ export function NoteNode({ data }: NodeProps<NoteNodeType>) {
5159
position={Position.Bottom}
5260
isConnectable={true}
5361
/>
54-
<div className="flex gap-1">
55-
<Emoji emoji={data.emoji} />
56-
<div>{data.title}</div>
62+
<div className="flex h-full w-full flex-col justify-between">
63+
<div className="flex w-full min-w-0 flex-row items-center justify-start gap-1">
64+
{data.emoji ? (
65+
<Emoji emoji={data.emoji} />
66+
) : (
67+
<FileText
68+
className="h-4 w-4 flex-shrink-0"
69+
strokeWidth="1.5px"
70+
color="#91918e"
71+
/>
72+
)}
73+
<div className="w-full truncate">{data.title}</div>
74+
</div>
75+
<ActiveUser
76+
className="self-end"
77+
users={activeUsers.filter(
78+
(user) => user.currentPageId === data.id.toString(),
79+
)}
80+
/>
5781
</div>
58-
<ActiveUser
59-
className="justify-end"
60-
users={users.filter(
61-
(user) => user.currentPageId === data.id.toString(),
62-
)}
63-
/>
6482
</div>
6583
);
6684
}

apps/frontend/src/components/commons/activeUser/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@ interface ActiveUserProps {
77
}
88

99
export default function ActiveUser({ users, className }: ActiveUserProps) {
10+
const maxVisibleUsers = 10;
11+
const hasMoreUsers = users.length > maxVisibleUsers;
12+
const visibleUsers = users.slice(0, maxVisibleUsers);
13+
1014
return (
11-
<div className={cn("flex gap-2", className)}>
12-
{users.map((user) => (
15+
<div className={cn("flex items-center", className)}>
16+
{visibleUsers.map((user, index) => (
1317
<div
1418
style={{ backgroundColor: user.color }}
15-
className={cn("group relative h-5 w-5 rounded-full")}
19+
className={cn(
20+
"group relative h-5 w-5 rounded-full",
21+
index !== 0 && "-ml-2",
22+
"hover:z-10",
23+
)}
1624
key={user.clientId}
1725
>
1826
<div
1927
style={{ backgroundColor: user.color }}
20-
className="absolute left-2 z-10 hidden px-2 text-sm group-hover:flex"
28+
className="absolute left-5 top-0 z-20 hidden max-w-28 truncate rounded-md px-2 py-1 text-sm text-white group-hover:block"
2129
>
2230
{user.clientId}
2331
</div>
2432
</div>
2533
))}
34+
{hasMoreUsers && (
35+
<div className="relative -ml-2 flex h-5 w-5 items-center justify-center rounded-full bg-gray-200 text-xs font-medium text-gray-600">
36+
+{users.length - maxVisibleUsers}
37+
</div>
38+
)}
2639
</div>
2740
);
2841
}

0 commit comments

Comments
 (0)