mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-09 04:02:40 -05:00
* Layout initial * Add FillRosterSection component * Move tournaments to feature folder * Refactor Button props * SubmitButton * Register action * Identifier -> Id * Invite link via nanoid * Team info submit * Enter tiebreaker map list UI * Invite members to tournament team initial * Show banner if joined a team not captain of * Add back teams page * Change team roster size color when good * Delete tournament team member
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import clsx from "clsx";
|
|
import type { User } from "~/db/types";
|
|
import * as React from "react";
|
|
import { BLANK_IMAGE_URL } from "~/utils/urls";
|
|
|
|
const dimensions = {
|
|
xxs: 24,
|
|
xs: 36,
|
|
sm: 44,
|
|
xsm: 62,
|
|
md: 81,
|
|
lg: 125,
|
|
} as const;
|
|
|
|
export function Avatar({
|
|
user,
|
|
size = "sm",
|
|
className,
|
|
alt = "",
|
|
...rest
|
|
}: {
|
|
user: Pick<User, "discordId" | "discordAvatar">;
|
|
className?: string;
|
|
alt?: string;
|
|
size: keyof typeof dimensions;
|
|
} & React.ButtonHTMLAttributes<HTMLImageElement>) {
|
|
const [isErrored, setIsErrored] = React.useState(false);
|
|
// TODO: just show text... my profile?
|
|
// TODO: also show this if discordAvatar is stale and 404's
|
|
|
|
React.useEffect(() => {
|
|
setIsErrored(false);
|
|
}, [user.discordAvatar]);
|
|
|
|
return (
|
|
<img
|
|
className={clsx("avatar", className)}
|
|
src={
|
|
user.discordAvatar && !isErrored
|
|
? `https://cdn.discordapp.com/avatars/${user.discordId}/${
|
|
user.discordAvatar
|
|
}.webp${size === "lg" ? "?size=240" : "?size=80"}`
|
|
: BLANK_IMAGE_URL // avoid broken image placeholder
|
|
}
|
|
alt={alt}
|
|
title={alt ? alt : undefined}
|
|
width={dimensions[size]}
|
|
height={dimensions[size]}
|
|
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3388
|
|
// eslint-disable-next-line react/no-unknown-property
|
|
onError={() => setIsErrored(true)}
|
|
{...rest}
|
|
/>
|
|
);
|
|
}
|