Skip to content

Commit

Permalink
fix: agent icon fallback only on error (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyjeong13 authored Mar 3, 2025
1 parent 58844d4 commit c4de7d0
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions ui/admin/app/components/agent/icon/AgentIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@ type AgentIconProps = {
export function AgentIcon({ icons, onChange, name }: AgentIconProps) {
const { theme } = useTheme();
const [imageUrlDialogOpen, setImageUrlDialogOpen] = useState(false);
const [showFallback, setShowFallback] = useState(false);

const { icon = "", iconDark = "" } = icons ?? {};
const isDarkMode = theme === AppTheme.Dark;
const obotIconIndex = iconOptions.findIndex((option) =>
icon.includes(option)
);

const handleLoadingStatusChange = (
status: "idle" | "loading" | "loaded" | "error"
) => {
// ignore loading & idle
if (status === "error") {
setShowFallback(true);
}
if (status === "loaded") {
setShowFallback(false);
}
};
return (
<>
<DropdownMenu>
Expand All @@ -99,10 +112,15 @@ export function AgentIcon({ icons, onChange, name }: AgentIconProps) {
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon-xl" className="group relative">
<Avatar className="size-20">
<AvatarImage src={iconDark && isDarkMode ? iconDark : icon} />
<AvatarFallback className="text-[3.5rem] font-semibold">
{name?.charAt(0) ?? ""}
</AvatarFallback>
<AvatarImage
src={iconDark && isDarkMode ? iconDark : icon}
onLoadingStatusChange={handleLoadingStatusChange}
/>
{showFallback && (
<AvatarFallback className="text-[3.5rem] font-semibold">
{name?.charAt(0) ?? ""}
</AvatarFallback>
)}
</Avatar>
<div className="absolute -right-1 top-0 items-center justify-center rounded-full bg-primary-foreground p-2 opacity-0 drop-shadow-md transition group-hover:opacity-100 group-focus:opacity-100">
<PencilIcon className="!size-4" />
Expand Down

0 comments on commit c4de7d0

Please sign in to comment.