diff --git a/frontend/app/room/[id]/sidebar-item.tsx b/frontend/app/room/[id]/sidebar-item.tsx index ad40bffc..af9c7709 100644 --- a/frontend/app/room/[id]/sidebar-item.tsx +++ b/frontend/app/room/[id]/sidebar-item.tsx @@ -11,7 +11,7 @@ import type { RoomEntity, UserOnRoomEntity, } from "@/app/lib/dtos"; -import { SmallAvatarSkeleton } from "@/app/ui/room/skeleton"; +import { Avatar } from "@/app/ui/user/avatar"; import { ContextMenu, ContextMenuContent, @@ -33,13 +33,6 @@ function truncateString(str: string | undefined, num: number): string { return str.slice(0, num) + "..."; } -function Avatar({ avatarURL }: { avatarURL?: string }) { - if (!avatarURL) { - return ; - } - return ; -} - export interface LeaveEvent { userId: number; roomId: number; @@ -110,7 +103,7 @@ export default function SidebarItem({ {!isKicked && ( - + {truncateString(user.user.name, 15)} {room.accessLevel !== "DIRECT" && isUserOwner && " 👑"} diff --git a/frontend/app/ui/user/avatar.tsx b/frontend/app/ui/user/avatar.tsx index 2e9e99e3..2e71db43 100644 --- a/frontend/app/ui/user/avatar.tsx +++ b/frontend/app/ui/user/avatar.tsx @@ -1,40 +1,78 @@ import { Skeleton } from "@/components/ui/skeleton"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import Link from "next/link"; export type AvatarSize = "small" | "medium" | "large"; -export function Avatar({ - avatarURL, - size, - alt, -}: { +export interface Props { avatarURL?: string; size: AvatarSize; + href?: string; alt?: string; -}) { + online?: boolean; +} + +export function Avatar({ avatarURL, size, href, alt, online }: Props) { let sizeClass = ""; + let onlineStatusClass = online ? "bg-green-500 " : "bg-gray-500 "; switch (size) { case "small": sizeClass = "h-6 w-6"; + onlineStatusClass += "w-3 h-3 border-2"; break; case "medium": sizeClass = "h-10 w-10"; + onlineStatusClass += "w-4 h-4 border-2"; break; case "large": - sizeClass = "h-32 w-32"; + sizeClass = "h-28 w-28"; + onlineStatusClass += "w-8 h-8 border-4"; break; default: - sizeClass = "h-10 w-10"; - break; + throw new Error("Invalid size"); } if (!avatarURL) { return ; - } else { - return ( - {alt} - ); } + const TooltipWrapper = ({ children }: { children: React.ReactNode }) => + alt !== undefined ? ( + + {children} + {alt} + + ) : ( + children + ); + const LinkWrapper = ({ children }: { children: React.ReactNode }) => + href !== undefined ? {children} : children; + return ( + +
+ + + {alt} + + + +
+
+ + {online ? "online" : "offline"} + +
+
+
+
+ ); } diff --git a/frontend/app/ui/user/match-history.tsx b/frontend/app/ui/user/match-history.tsx index 77972a4c..6ba06347 100644 --- a/frontend/app/ui/user/match-history.tsx +++ b/frontend/app/ui/user/match-history.tsx @@ -1,6 +1,5 @@ import { getMatchHistory } from "@/app/lib/actions"; import type { MatchDetailEntity } from "@/app/lib/dtos"; -import Link from "next/link"; import { Avatar } from "./avatar"; import ProfileItem from "./profile-item"; @@ -17,17 +16,19 @@ function MatchDetailItem({ : "text-red-500" : ""; return ( - -
-
- -
{detail.user.name}
-
- {detail.winLose} ({detail.score}) -
+
+
+ +
{detail.user.name}
+
+ {detail.winLose} ({detail.score})
- +
); } diff --git a/frontend/app/ui/user/user-list.tsx b/frontend/app/ui/user/user-list.tsx index bd9c3d33..6e546d09 100644 --- a/frontend/app/ui/user/user-list.tsx +++ b/frontend/app/ui/user/user-list.tsx @@ -1,7 +1,6 @@ import type { PublicUserEntity } from "@/app/lib/dtos"; import { TooltipProvider } from "@/components/ui/tooltip"; -import { AvatarSize } from "./avatar"; -import UserTooltip from "./user-tool-tip"; +import { Avatar, AvatarSize } from "./avatar"; export default function UserList({ users, @@ -15,7 +14,13 @@ export default function UserList({
{users.length === 0 &&
No users to display
} {users.map((u) => ( - + ))}
diff --git a/frontend/app/ui/user/user-tool-tip.tsx b/frontend/app/ui/user/user-tool-tip.tsx deleted file mode 100644 index 76f76ecd..00000000 --- a/frontend/app/ui/user/user-tool-tip.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import type { PublicUserEntity } from "@/app/lib/dtos"; -import { - Tooltip, - TooltipContent, - TooltipTrigger, -} from "@/components/ui/tooltip"; -import Link from "next/link"; -import { Avatar, AvatarSize } from "./avatar"; - -// This component has to be used with TooltipProvider -export default function UserTooltip({ - user, - avatarSize, -}: { - user: PublicUserEntity; - avatarSize: AvatarSize; -}) { - return ( - - - - - - - {user.name} - - ); -}