Skip to content

Commit 3384b3e

Browse files
committed
fix: 같은 clientId에 대한 커서 필터
1 parent 4783d27 commit 3384b3e

File tree

1 file changed

+17
-9
lines changed
  • apps/frontend/src/features/canvas/ui/CollaborativeCursors

1 file changed

+17
-9
lines changed

apps/frontend/src/features/canvas/ui/CollaborativeCursors/index.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ interface CollaborativeCursorsProps {
1313
export function CollaborativeCursors({ cursors }: CollaborativeCursorsProps) {
1414
const { flowToScreenPosition } = useReactFlow();
1515
const { currentUser } = useUserStore();
16-
const validCursors = useMemo(
17-
() =>
18-
Array.from(cursors.values()).filter(
19-
(cursor) =>
20-
cursor.cursor &&
21-
(cursor.clientId as unknown as string) !== currentUser.clientId,
22-
),
23-
[cursors],
24-
);
16+
const validCursors = useMemo(() => {
17+
const filteredCursors = Array.from(cursors.values()).filter(
18+
(cursor) =>
19+
cursor.cursor &&
20+
(cursor.clientId as unknown as string) !== currentUser.clientId,
21+
);
22+
23+
const uniqueCursors = filteredCursors.reduce((acc, current) => {
24+
const exists = acc.find((item) => item.clientId === current.clientId);
25+
if (!exists) {
26+
acc.push(current);
27+
}
28+
return acc;
29+
}, [] as AwarenessState[]);
30+
31+
return uniqueCursors;
32+
}, [cursors]);
2533

2634
return (
2735
<Panel>

0 commit comments

Comments
 (0)