-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔄 Merge pull request #15 from steeeee0223/feature/worxpace
Setup `liveblocks`
- Loading branch information
Showing
16 changed files
with
863 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
apps/worxpace/src/app/(platform)/(tools)/_components/participants.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client"; | ||
|
||
import { MAX_SHOWN_USERS } from "~/constants/site"; | ||
import { connectionIdToColor } from "~/lib"; | ||
import { useOthers, useSelf } from "~/liveblocks.config"; | ||
import UserAvatar from "./user-avatar"; | ||
|
||
const Participants = () => { | ||
const currentUser = useSelf(); | ||
const otherUsers = useOthers(); | ||
const hasMoreUsers = otherUsers.length > MAX_SHOWN_USERS; | ||
|
||
return ( | ||
<div className="flex"> | ||
{currentUser && ( | ||
<UserAvatar | ||
borderColor={connectionIdToColor(currentUser.connectionId)} | ||
src={currentUser.info?.picture} | ||
name={`${currentUser.info?.name} (You)`} | ||
fallback={currentUser.info?.name?.[0]} | ||
className="ml-[-8px]" | ||
/> | ||
)} | ||
{otherUsers.slice(0, MAX_SHOWN_USERS).map(({ connectionId, info }) => ( | ||
<UserAvatar | ||
borderColor={connectionIdToColor(connectionId)} | ||
key={connectionId} | ||
src={info?.picture} | ||
name={info?.name} | ||
fallback={info?.name?.[0] ?? "T"} | ||
className="ml-[-8px]" | ||
/> | ||
))} | ||
{hasMoreUsers && ( | ||
<UserAvatar | ||
name={`${otherUsers.length - MAX_SHOWN_USERS} more`} | ||
fallback={`+${otherUsers.length - MAX_SHOWN_USERS}`} | ||
className="ml-[-8px]" | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Participants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/worxpace/src/app/(platform)/(tools)/_components/user-avatar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Avatar, AvatarFallback, AvatarImage, Hint } from "@acme/ui/components"; | ||
import { cn } from "@acme/ui/lib"; | ||
|
||
interface UserAvatarProps { | ||
src?: string; | ||
name?: string; | ||
fallback?: string; | ||
borderColor?: string; | ||
className?: string; | ||
} | ||
|
||
const UserAvatar = ({ | ||
src, | ||
name, | ||
fallback, | ||
borderColor, | ||
className, | ||
}: UserAvatarProps) => { | ||
return ( | ||
<Hint | ||
asChild | ||
description={name ?? "Teammate"} | ||
side="bottom" | ||
sideOffset={18} | ||
> | ||
<Avatar | ||
className={cn("h-6 w-6 border-2", className)} | ||
style={{ borderColor }} | ||
> | ||
<AvatarImage src={src} /> | ||
<AvatarFallback className="text-xs font-semibold"> | ||
{fallback} | ||
</AvatarFallback> | ||
</Avatar> | ||
</Hint> | ||
); | ||
}; | ||
|
||
export default UserAvatar; |
Oops, something went wrong.