import { For, Show, createEffect, createSignal } from "solid-js"; import { createResource } from "@/lib/create-resource"; import { getRagThreads } from "@/api/rag"; import type { RagThread } from "@/api/client"; import { EmptyInline } from "@/components/ui/empty-inline"; import { IconEdit, IconTrash } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { TableRowActions } from "@/components/ui/table-row-actions"; import { cn } from "@/lib/cn"; import type { Locale } from "@/i18n/messages"; // One growing page instead of numbered pages: a chat sidebar scrolls, it does // not paginate. The API caps a page at 500 rows. const THREAD_PAGE_SIZE = 40; const THREAD_PAGE_MAX = 500; export function RagThreadList(props: { activeId?: string; version: number; locale: Locale; labels: { untitled: string; emptyThreads: string; emptyThreadsHint: string; rename: string; actions: string; delete: string; loadMore: string; threadsFailed: string; tryAgain: string; groupToday: string; groupYesterday: string; groupThisWeek: string; groupEarlier: string; }; /** Every thread the list holds, for callers that need a title by id. */ onThreads?: (threads: RagThread[]) => void; onOpen: (thread: RagThread) => void; onRename: (thread: RagThread) => void; onRemove: (thread: RagThread) => void; }) { const [limit, setLimit] = createSignal(THREAD_PAGE_SIZE); const [threads, { refetch }] = createResource( () => ({ limit: limit(), version: props.version }), ({ limit }) => getRagThreads({ limit, offset: 0 }), ); createEffect(() => { const result = threads.latest; if (result) props.onThreads?.(result.items); }); const hasMore = () => { const result = threads.latest; return !!result && result.total > result.items.length && limit() < THREAD_PAGE_MAX; }; return (
{/* A failed first read used to spin forever: `latest` never arrives. */} }> {(result) => ( 0} fallback={} >
    {(thread) => { const active = () => thread.id === props.activeId; return (
  • {/* The row menu shows on hover, on keyboard focus and on the open chat. */}
    , onSelect: () => props.onRename(thread) }, { label: props.labels.delete, icon: , destructive: true, onSelect: () => props.onRemove(thread) }, ]} />
  • ); }}
)}
); }