import { useState } from "react";
import { API_URL } from "../config/api.ts";
interface AvatarProps {
userId: string;
username: string;
hasAvatar: boolean;
size?: number;
version?: number;
}
export function Avatar(
{ userId, username, hasAvatar, size = 36, version }: AvatarProps,
) {
const [imgFailed, setImgFailed] = useState(false);
const sizeStyle = { width: size, height: size };
if (hasAvatar && !imgFailed) {
const src = version
? `${API_URL}/api/avatars/${userId}?v=${version}`
: `${API_URL}/api/avatars/${userId}`;
return (
setImgFailed(true)}
/>
);
}
return (