import { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
import { urlAvatar } from "@/lib/avatar-store";
export function Avatar({
id,
fallback,
className,
alt,
bust,
}: {
id: string;
fallback: string;
className?: string;
alt?: string;
/** Forza il ricaricamento ignorando la cache: usato dopo aver cambiato la propria foto. */
bust?: number;
}) {
const [errore, setErrore] = useState(false);
useEffect(() => setErrore(false), [id, bust]);
if (!errore) {
const src = bust ? `${urlAvatar(id)}?v=${bust}` : urlAvatar(id);
return (
setErrore(true)}
className={cn("aspect-square shrink-0 rounded-2xl object-cover", className)}
/>
);
}
return (
{fallback}
);
}