File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Panel } from "@xyflow/react";
22import { useReactFlow } from "@xyflow/react" ;
33import { type AwarenessState } from "@/hooks/useCursor" ;
44import Cursor from "./cursor" ;
5+ import { useMemo } from "react" ;
56
67interface CollaborativeCursorsProps {
78 cursors : Map < number , AwarenessState > ;
@@ -10,20 +11,23 @@ interface CollaborativeCursorsProps {
1011export function CollaborativeCursors ( { cursors } : CollaborativeCursorsProps ) {
1112 const { flowToScreenPosition } = useReactFlow ( ) ;
1213
13- return (
14- < Panel position = "top-left" className = "pointer-events-none" >
15- { Array . from ( cursors . values ( ) ) . map ( ( cursor ) => {
16- if ( ! cursor . cursor ) return null ;
17-
18- const position = flowToScreenPosition ( {
19- x : cursor . cursor . x ,
20- y : cursor . cursor . y ,
21- } ) ;
14+ const validCursors = useMemo (
15+ ( ) => Array . from ( cursors . values ( ) ) . filter ( ( cursor ) => cursor . cursor ) ,
16+ [ cursors ] ,
17+ ) ;
2218
23- return (
24- < Cursor key = { cursor . clientId } coors = { position } color = { cursor . color } />
25- ) ;
26- } ) }
19+ return (
20+ < Panel >
21+ { validCursors . map ( ( cursor ) => (
22+ < Cursor
23+ key = { cursor . clientId }
24+ coors = { flowToScreenPosition ( {
25+ x : cursor . cursor ! . x ,
26+ y : cursor . cursor ! . y ,
27+ } ) }
28+ color = { cursor . color }
29+ />
30+ ) ) }
2731 </ Panel >
2832 ) ;
2933}
You can’t perform that action at this time.
0 commit comments