@@ -8,8 +8,10 @@ import { RoomSharingDialog } from "./RoomSharingDialog";
88import { usePathname } from "next/navigation" ;
99import { CollaborationAdDialog } from "./CollaborationAdDialog" ;
1010import { cn } from "@/lib/utils" ;
11+ import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "./ui/tooltip" ;
12+ import { RoomParticipants } from "@repo/common/types" ;
1113
12- export default function CollaborationStartBtn ( { slug, participantsCount } : { slug ?: string , participantsCount ?: number } ) {
14+ export default function CollaborationStartBtn ( { slug, participants } : { slug ?: string , participants ?: RoomParticipants [ ] } ) {
1315 const pathname = usePathname ( ) ;
1416 const [ isOpen , setIsOpen ] = useState ( false ) ;
1517 const { data : session } = useSession ( ) ;
@@ -18,10 +20,32 @@ export default function CollaborationStartBtn({ slug, participantsCount }: { slu
1820
1921 return (
2022 < div className = "Start_Room_Session transition-transform duration-500 ease-in-out flex items-center justify-end" >
23+ < div className = "UserList__wrapper flex w-full justify-end items-center" >
24+ < div className = "UserList p-1 flex flex-wrap justify-end items-center gap-[.625rem]" >
25+ < TooltipProvider delayDuration = { 0 } >
26+ < div className = "flex space-x-2" >
27+ { participants ?. map ( ( participant ) => (
28+ < Tooltip key = { participant . userId } >
29+ < TooltipTrigger asChild >
30+ < div style = { { backgroundColor : getClientColor ( participant ) } } className = { `w-7 h-7 rounded-full flex items-center justify-center cursor-pointer` } >
31+ < span className = "text-sm font-bold text-gray-900 dark:text-gray-100" >
32+ { participant . userName . charAt ( 0 ) }
33+ </ span >
34+ </ div >
35+ </ TooltipTrigger >
36+ < TooltipContent >
37+ { participant . userName }
38+ </ TooltipContent >
39+ </ Tooltip >
40+ ) ) }
41+ </ div >
42+ </ TooltipProvider >
43+ </ div >
44+ </ div >
2145 < Button type = "button" onClick = { ( ) => setIsOpen ( true ) }
2246 className = { cn ( "excalidraw-button collab-button relative w-auto py-3 px-4 rounded-md text-[.875rem] font-semibold shadow-none active:scale-[.98]" , roomSlug ? "bg-[#0fb884] dark:bg-[#0fb884] hover:bg-[#0fb884]" : "bg-color-primary hover:bg-brand-hover active:bg-brand-active" ) }
23- title = "Live collaboration..." > Share { roomSlug && participantsCount && participantsCount > 0 && (
24- < div className = "CollabButton-collaborators text-[.6rem] text-[#2b8a3e] bg-[#b2f2bb] font-bold font-assistant rounded-[50%] p-1 min-w-4 min-h-4 w-4 h-4 flex items-center justify-center absolute bottom-[-5px] right-[-5px]" > { participantsCount } </ div >
47+ title = "Live collaboration..." > Share { roomSlug && participants && participants . length > 0 && (
48+ < div className = "CollabButton-collaborators text-[.6rem] text-[#2b8a3e] bg-[#b2f2bb] font-bold font-assistant rounded-[50%] p-1 min-w-4 min-h-4 w-4 h-4 flex items-center justify-center absolute bottom-[-5px] right-[-5px]" > { participants . length } </ div >
2549 ) } </ Button >
2650
2751 { session ?. user && session ?. user . id ? (
@@ -35,4 +59,26 @@ export default function CollaborationStartBtn({ slug, participantsCount }: { slu
3559 ) }
3660 </ div >
3761 )
38- }
62+ }
63+
64+ function hashToInteger ( id : string ) {
65+ let hash = 0 ;
66+ if ( ! id ) return hash ;
67+
68+ for ( let i = 0 ; i < id . length ; i ++ ) {
69+ const char = id . charCodeAt ( i ) ;
70+ hash = ( hash << 5 ) - hash + char ;
71+ }
72+ return hash ;
73+ }
74+
75+ export const getClientColor = ( collaborator : { userId : string ; userName : string ; } ) => {
76+ if ( ! collaborator ?. userId ) return "hsl(0, 0%, 83%)" ;
77+
78+ const hash = Math . abs ( hashToInteger ( collaborator ?. userId ) ) ;
79+ const hue = ( hash % 36 ) * 10 ;
80+ const saturation = 90 ;
81+ const lightness = 75 ;
82+
83+ return `hsl(${ hue } , ${ saturation } %, ${ lightness } %)` ;
84+ } ;
0 commit comments