Files
wehub-resource-sync e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

81 lines
2.7 KiB
TypeScript

"use client";
import type { CloudThread } from "@assistant-ui/cloud-ai-sdk";
import { cn } from "@/lib/utils";
import { Plus, Trash2, MessageSquare } from "lucide-react";
type ThreadListProps = {
threads: CloudThread[];
selectedId: string | null;
onSelect: (id: string | null) => void;
onDelete: (id: string) => void;
isLoading: boolean;
};
export function ThreadList({
threads,
selectedId,
onSelect,
onDelete,
isLoading,
}: ThreadListProps) {
return (
<div className="bg-sidebar flex h-full w-64 shrink-0 flex-col border-r">
<div className="p-3">
<button
type="button"
onClick={() => onSelect(null)}
className="border-sidebar-border bg-sidebar text-sidebar-foreground hover:bg-sidebar-accent flex w-full items-center justify-center gap-2 rounded-lg border px-4 py-2 text-sm font-medium transition-colors"
>
<Plus className="size-4" />
New Chat
</button>
</div>
<div className="flex-1 overflow-y-auto px-2 pb-2">
{isLoading && threads.length === 0 ? (
<div className="text-muted-foreground flex items-center justify-center py-8 text-sm">
Loading...
</div>
) : threads.length === 0 ? (
<div className="text-muted-foreground flex flex-col items-center justify-center gap-2 py-8 text-center text-sm">
<MessageSquare className="size-6 opacity-40" />
<p>No conversations yet</p>
</div>
) : (
<div className="space-y-0.5">
{threads.map((thread) => (
<button
type="button"
key={thread.id}
onClick={() => onSelect(thread.id)}
className={cn(
"group flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors",
selectedId === thread.id
? "bg-sidebar-accent text-sidebar-accent-foreground"
: "text-sidebar-foreground hover:bg-sidebar-accent/50",
)}
>
<span className="flex-1 truncate">
{thread.title || "New conversation"}
</span>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
onDelete(thread.id);
}}
className="shrink-0 opacity-0 transition-opacity group-hover:opacity-100"
aria-label="Delete thread"
>
<Trash2 className="text-muted-foreground hover:text-destructive size-3.5" />
</button>
</button>
))}
</div>
)}
</div>
</div>
);
}