Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/features/modes/router/components/RecentChats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Chat: Recent Chats — shows 3 most recently
// interacted chats on the homepage (compact row)
// ──────────────────────────────────────────────
import { useMemo } from "react";
import { useEffect, useMemo, useState } from "react";
import { MessageSquare, BookOpen } from "lucide-react";
import { useRecentChatSummaries, type ChatListItem } from "../../../catalog/chats/index";
import { characterAvatarUrl, useCharacterSummariesByIds } from "../../../catalog/characters/index";
Expand Down Expand Up @@ -105,19 +105,8 @@ function RecentChatChip({
>
{/* Small avatar with mode dot */}
<div className="relative flex-shrink-0">
{firstAvatar?.avatarUrl ? (
<span className="relative block h-5 w-5 overflow-hidden rounded-md">
<img
src={firstAvatar.avatarUrl}
alt={firstAvatar.name}
className="h-full w-full object-cover"
style={getAvatarCropStyle(firstAvatar.avatarCrop)}
/>
</span>
) : firstAvatar ? (
<div className="flex h-5 w-5 items-center justify-center rounded-md bg-[var(--secondary)] text-[0.5rem] font-bold text-[var(--muted-foreground)]">
{firstAvatar.name[0]}
</div>
{firstAvatar ? (
<RecentChatAvatar avatar={firstAvatar} />
) : (
<div
className="flex h-5 w-5 items-center justify-center rounded-md text-white"
Expand All @@ -142,3 +131,35 @@ function RecentChatChip({
</button>
);
}

function RecentChatAvatar({
avatar,
}: {
avatar: { name: string; avatarUrl: string | null; avatarCrop?: AvatarCropValue | null };
}) {
const [imageFailed, setImageFailed] = useState(false);

useEffect(() => {
setImageFailed(false);
}, [avatar.avatarUrl]);

if (!avatar.avatarUrl || imageFailed) {
return (
<div className="flex h-5 w-5 items-center justify-center rounded-md bg-[var(--secondary)] text-[0.5rem] font-bold text-[var(--muted-foreground)]">
{avatar.name[0]}
</div>
);
}

return (
<span className="relative block h-5 w-5 overflow-hidden rounded-md">
<img
src={avatar.avatarUrl}
alt={avatar.name}
className="h-full w-full object-cover"
style={getAvatarCropStyle(avatar.avatarCrop)}
onError={() => setImageFailed(true)}
/>
</span>
);
}
Loading