-
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.
[frontend] Add online status to user avatar (#214)
- Loading branch information
Showing
8 changed files
with
122 additions
and
75 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
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 |
---|---|---|
@@ -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 <Skeleton className={`flex-none rounded-full ${sizeClass}`} />; | ||
} else { | ||
return ( | ||
<img | ||
className={`flex-none rounded-full object-cover ${sizeClass}`} | ||
src={avatarURL} | ||
alt={alt} | ||
/> | ||
); | ||
} | ||
const TooltipWrapper = ({ children }: { children: React.ReactNode }) => | ||
alt !== undefined ? ( | ||
<Tooltip> | ||
<TooltipTrigger asChild>{children}</TooltipTrigger> | ||
<TooltipContent>{alt}</TooltipContent> | ||
</Tooltip> | ||
) : ( | ||
children | ||
); | ||
const LinkWrapper = ({ children }: { children: React.ReactNode }) => | ||
href !== undefined ? <Link href={href}>{children}</Link> : children; | ||
return ( | ||
<LinkWrapper> | ||
<div className={`relative flex-none ${sizeClass}`}> | ||
<TooltipProvider delayDuration={0}> | ||
<TooltipWrapper> | ||
<img | ||
className={`rounded-full object-cover ${sizeClass}`} | ||
src={avatarURL} | ||
alt={alt} | ||
/> | ||
</TooltipWrapper> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<div | ||
className={`absolute -bottom-[2px] -right-[2px] border-background rounded-full ${onlineStatusClass}`} | ||
></div> | ||
</TooltipTrigger> | ||
<TooltipContent sideOffset={-2}> | ||
{online ? "online" : "offline"} | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</div> | ||
</LinkWrapper> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.