forge
Explore
Log in

Don't you dare go Hollow

✨ paginated chat history view in Çelebi

Browse files at this commit

39c877702a08e25ef75515e7d82bb7209e5711c9Burak BoduroğluParent: 13c17b2
  • feat
    • ✨ paginated chat history view in Çelebi
Show full message
feat: ✨ paginated chat history view in Çelebi
- replace the horizontal thread chip strip with a Chats view that pages
  through history server-side (limit/offset, 10 per page)
- header shows the open chat title with New chat and Chats actions
- the chat stays mounted while history is open, restoring its scroll
  position on return; EN/TR copy for the new labels
src/components/layout/celebi-panel.tsxmodified+77 -29
@@ -1,4 +1,4 @@
1-import { For, Match, Show, Switch, createEffect, createSignal, onCleanup, untrack } from "solid-js";
1+import { For, Match, Show, Switch, createEffect, createSignal, on, onCleanup, untrack } from "solid-js";
22 import { useNavigate } from "@tanstack/solid-router";
33 import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot";
44 import { formatApiError } from "@/api/client";
@@ -6,10 +6,11 @@ import { CelebiComposer } from "@/components/layout/celebi-composer";
66 import { CelebiMarkdown } from "@/components/layout/celebi-markdown";
77 import { CelebiReplyActions } from "@/components/layout/celebi-reply-actions";
88 import { CelebiThinkingLabel } from "@/components/layout/celebi-thinking-label";
9+import { CelebiThreadList } from "@/components/layout/celebi-thread-list";
910 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
1011 import { DataTableSearch } from "@/components/ui/data-table-search";
1112 import { EmptyInline } from "@/components/ui/empty-inline";
12-import { IconAlert, IconBotSquare, IconChevronDown, IconCopy, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons";
13+import { IconAlert, IconBotSquare, IconChevronDown, IconChevronLeft, IconCopy, IconEdit, IconMessage, IconPlus } from "@/components/ui/icons";
1314 import { SidePanel } from "@/components/ui/side-panel";
1415 import { cn } from "@/lib/cn";
1516 import { usePreferences, useT } from "@/stores/preferences-context";
@@ -32,7 +33,11 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
3233 const [draft, setDraft] = createSignal("");
3334 const [messages, setMessages] = createSignal<PanelMessage[]>([]);
3435 const [threadId, setThreadId] = createSignal<string>();
35- const [threads, setThreads] = createSignal<ChatbotThread[]>([]);
36+ const [threadTitle, setThreadTitle] = createSignal<string | null>(null);
37+ // History lives in its own view so a long list pages instead of piling up
38+ // as chips above the transcript.
39+ const [view, setView] = createSignal<"chat" | "threads">("chat");
40+ const [threadsVersion, setThreadsVersion] = createSignal(0);
3641 const [sending, setSending] = createSignal(false);
3742 const [copiedId, setCopiedId] = createSignal<string>();
3843 const [searchQuery, setSearchQuery] = createSignal("");
@@ -111,7 +116,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
111116 transcript.scrollTo({ top: transcript.scrollHeight, behavior: "smooth" });
112117 };
113118 const handleTranscriptScroll = () => {
114- if (!transcript) return;
119+ if (!transcript || view() !== "chat") return;
115120 const top = transcript.scrollTop;
116121 const distance = transcript.scrollHeight - top - transcript.clientHeight;
117122 // A shrinking transcript (search filtering) clamps scrollTop down too, but
@@ -138,6 +143,18 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
138143 requestAnimationFrame(() => { if (pinned()) pinToBottom(); });
139144 });
140145
146+ // `display: none` can drop a scroll offset, so coming back from the history
147+ // view restores it: the bottom when pinned, else where the reader left off.
148+ createEffect(on(view, (current, previous) => {
149+ if (current !== "chat" || previous !== "threads") return;
150+ const saved = lastScrollTop;
151+ requestAnimationFrame(() => {
152+ if (!transcript) return;
153+ if (pinned()) pinToBottom();
154+ else transcript.scrollTop = lastScrollTop = saved;
155+ });
156+ }));
157+
141158 let pollTimer: number | undefined;
142159 let stream: EventSource | undefined;
143160
@@ -146,15 +163,27 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
146163 pollTimer = undefined;
147164 };
148165 const stopStream = () => { stream?.close(); stream = undefined; };
149- const loadThreads = async () => { try { setThreads((await getChatbotThreads({ limit: 100 })).items); } catch { /* history is non-blocking */ } };
150- const openThread = async (id: string) => { stopPolling(); stopStream(); stopReveal(); setPinned(true); setUnread(false); setThreadId(id); setMessages((await getChatbotThreadMessages(id, { limit: 500 })).items); };
151- const createThread = () => { stopPolling(); stopStream(); stopReveal(); setThreadId(undefined); setMessages([]); };
166+ // The history view refetches its page on the version bump; the header title
167+ // of the open chat is refreshed from the newest threads, where it sits once
168+ // it has just been written to.
169+ const loadThreads = async () => {
170+ setThreadsVersion((version) => version + 1);
171+ const active = threadId();
172+ if (!active) return;
173+ try {
174+ const match = (await getChatbotThreads({ limit: 10 })).items.find((thread) => thread.id === active);
175+ if (match && threadId() === active) setThreadTitle(match.title);
176+ } catch { /* history is non-blocking */ }
177+ };
178+ const openThread = async (thread: ChatbotThread) => { stopPolling(); stopStream(); stopReveal(); setPinned(true); setUnread(false); setView("chat"); setSearchQuery(""); setThreadId(thread.id); setThreadTitle(thread.title); setMessages((await getChatbotThreadMessages(thread.id, { limit: 500 })).items); };
179+ const createThread = () => { stopPolling(); stopStream(); stopReveal(); setSearchQuery(""); setThreadId(undefined); setThreadTitle(null); setMessages([]); };
152180 // Rename and delete go through the shared confirm dialog, never the
153181 // browser's own prompt()/confirm() boxes.
154182 const [renaming, setRenaming] = createSignal<ChatbotThread | null>(null);
155183 const [removing, setRemoving] = createSignal<ChatbotThread | null>(null);
156184 const renameThread = async (thread: ChatbotThread, title: string | undefined) => {
157- await patchChatbotThreadById(thread.id, { title: title?.trim() || null });
185+ const updated = await patchChatbotThreadById(thread.id, { title: title?.trim() || null });
186+ if (threadId() === thread.id) setThreadTitle(updated.title);
158187 await loadThreads();
159188 };
160189 const removeThread = async (thread: ChatbotThread) => {
@@ -162,7 +191,6 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
162191 if (threadId() === thread.id) createThread();
163192 await loadThreads();
164193 };
165- createEffect(() => { if (props.open) void loadThreads(); });
166194
167195 const failureMessage = (code: string | null) => {
168196 if (locale() === "tr") return code ? `Yanıt alınamadı (${code}).` : "Yanıt alınamadı. Lütfen tekrar dene.";
@@ -253,27 +281,46 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
253281 return (
254282 <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("ai.title")} description={t("ai.description")} bodyClass="overflow-hidden">
255283 <div class="flex h-full min-h-0 flex-col">
256- <div class="mb-3 flex shrink-0 gap-2 overflow-x-auto border-b border-border pb-3">
257- <button type="button" class="flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-card px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent" onClick={createThread}>
258- <IconPlus class="h-3.5 w-3.5" />
259- {locale() === "tr" ? "Yeni sohbet" : "New chat"}
260- </button>
261- <For each={threads()}>
262- {(thread) => (
263- <div class={cn("flex h-8 shrink-0 items-center overflow-hidden rounded-lg border border-border", thread.id === threadId() ? "bg-accent" : "bg-card")}>
264- <button type="button" class="max-w-[10rem] truncate px-2.5 text-xs text-foreground" onClick={() => void openThread(thread.id)}>
265- {thread.title || (locale() === "tr" ? "Adsız sohbet" : "Untitled chat")}
266- </button>
267- <button type="button" class="flex h-full w-7 items-center justify-center border-l border-border text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" aria-label={locale() === "tr" ? "Sohbeti yeniden adlandır" : "Rename chat"} onClick={() => setRenaming(thread)}>
268- <IconEdit class="h-3.5 w-3.5" />
269- </button>
270- <button type="button" class="flex h-full w-7 items-center justify-center border-l border-border text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive" aria-label={locale() === "tr" ? "Sohbeti sil" : "Delete chat"} onClick={() => setRemoving(thread)}>
271- <IconTrash class="h-3.5 w-3.5" />
272- </button>
273- </div>
274- )}
275- </For>
284+ <div class="mb-3 flex shrink-0 items-center gap-2 border-b border-border pb-3">
285+ <Show
286+ when={view() === "chat"}
287+ fallback={
288+ <button type="button" class="flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-card px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent" onClick={() => setView("chat")}>
289+ <IconChevronLeft class="h-3.5 w-3.5" />
290+ {t("common.back")}
291+ </button>
292+ }
293+ >
294+ <button type="button" class="flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-card px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent" onClick={createThread}>
295+ <IconPlus class="h-3.5 w-3.5" />
296+ {t("ai.newChat")}
297+ </button>
298+ </Show>
299+ <span class="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
300+ {view() === "threads" ? t("ai.chats") : threadId() ? threadTitle() || t("ai.untitledChat") : t("ai.newChat")}
301+ </span>
302+ <Show when={view() === "chat"}>
303+ <button type="button" class="flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-border bg-card px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent" onClick={() => setView("threads")}>
304+ <IconMessage class="h-3.5 w-3.5" />
305+ {t("ai.chats")}
306+ </button>
307+ </Show>
276308 </div>
309+ <Show when={view() === "threads"}>
310+ <div class="min-h-0 flex-1">
311+ <CelebiThreadList
312+ activeId={threadId()}
313+ version={threadsVersion()}
314+ onOpen={(thread) => void openThread(thread)}
315+ onRename={setRenaming}
316+ onRemove={setRemoving}
317+ />
318+ </div>
319+ </Show>
320+ {/* Hidden rather than unmounted while the history is open, so going
321+ back lands on the same scroll position and a streaming answer
322+ keeps writing. */}
323+ <div class={cn("flex min-h-0 flex-1 flex-col", view() !== "chat" && "hidden")}>
277324 <div class="mb-3 shrink-0">
278325 <DataTableSearch value={searchQuery()} onChange={setSearchQuery} placeholder={t("ai.searchPlaceholder")} class="w-full" />
279326 </div>
@@ -380,6 +427,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
380427 disabled={!draft().trim() || sending()}
381428 />
382429 </div>
430+ </div>
383431 </div>
384432 <ConfirmDialog
385433 open={renaming() != null}
src/components/layout/celebi-thread-list.tsxadded+78 -0
@@ -0,0 +1,78 @@
1+import { For, Show, createEffect, createResource, createSignal, on } from "solid-js";
2+import { getChatbotThreads, type ChatbotThread } from "@/api/chatbot";
3+import { EmptyInline } from "@/components/ui/empty-inline";
4+import { IconEdit, IconTrash } from "@/components/ui/icons";
5+import { PageSpinner } from "@/components/ui/page-spinner";
6+import { PaginationControls } from "@/components/ui/pagination-controls";
7+import { cn } from "@/lib/cn";
8+import { formatDateTime } from "@/lib/format";
9+import { usePreferences, useT } from "@/stores/preferences-context";
10+
11+const THREAD_PAGE_SIZE = 10;
12+
13+/**
14+ * Chat history as its own view inside the Çelebi panel. Pages come from the
15+ * server (`limit`/`offset`), so a long history never loads whole or turns the
16+ * panel header into an endless strip of chips.
17+ */
18+export function CelebiThreadList(props: {
19+ activeId?: string;
20+ /** Bumped by the panel after a rename, delete, or new answer to refetch the page. */
21+ version: number;
22+ onOpen: (thread: ChatbotThread) => void;
23+ onRename: (thread: ChatbotThread) => void;
24+ onRemove: (thread: ChatbotThread) => void;
25+}) {
26+ const t = useT();
27+ const { locale } = usePreferences();
28+ const [page, setPage] = createSignal(0);
29+ const [threads] = createResource(
30+ () => ({ page: page(), version: props.version }),
31+ ({ page }) => getChatbotThreads({ limit: THREAD_PAGE_SIZE, offset: page * THREAD_PAGE_SIZE }),
32+ );
33+ const totalPages = () => Math.max(1, Math.ceil((threads.latest?.total ?? 0) / THREAD_PAGE_SIZE));
34+
35+ // Deleting the last chat on the last page leaves that page empty; step back.
36+ createEffect(on(() => threads.latest, (result) => {
37+ if (result && result.items.length === 0 && page() > 0) setPage(Math.min(page() - 1, totalPages() - 1));
38+ }));
39+
40+ return (
41+ <div class="flex h-full min-h-0 flex-col">
42+ <div class="min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1">
43+ <Show when={threads.latest} fallback={<Show when={threads.loading}><PageSpinner /></Show>}>
44+ {(result) => (
45+ <Show
46+ when={result().items.length > 0}
47+ fallback={<EmptyInline class="h-full py-10" size="md" illustration="messages" title={t("ai.chats")} hint={t("ai.noChats")} />}
48+ >
49+ <ul class="flex flex-col gap-1.5">
50+ <For each={result().items}>
51+ {(thread) => (
52+ <li class={cn("flex items-center overflow-hidden rounded-lg border border-border", thread.id === props.activeId ? "bg-accent" : "bg-card")}>
53+ <button type="button" class="flex min-w-0 flex-1 flex-col items-start gap-0.5 px-3 py-2 text-left transition-colors hover:bg-muted" onClick={() => props.onOpen(thread)}>
54+ <span class="w-full truncate text-sm font-medium text-foreground">{thread.title || t("ai.untitledChat")}</span>
55+ <span class="text-xs text-muted-foreground">{formatDateTime(thread.updated_at, locale())}</span>
56+ </button>
57+ <button type="button" class="flex h-full min-h-12 w-9 items-center justify-center border-l border-border text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" aria-label={t("ai.renameChat")} onClick={() => props.onRename(thread)}>
58+ <IconEdit class="h-3.5 w-3.5" />
59+ </button>
60+ <button type="button" class="flex h-full min-h-12 w-9 items-center justify-center border-l border-border text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive" aria-label={t("ai.deleteChat")} onClick={() => props.onRemove(thread)}>
61+ <IconTrash class="h-3.5 w-3.5" />
62+ </button>
63+ </li>
64+ )}
65+ </For>
66+ </ul>
67+ </Show>
68+ )}
69+ </Show>
70+ </div>
71+ <Show when={totalPages() > 1}>
72+ <div class="mt-3 shrink-0">
73+ <PaginationControls page={page()} totalPages={totalPages()} onPageChange={setPage} />
74+ </div>
75+ </Show>
76+ </div>
77+ );
78+}
src/i18n/messages.tsmodified+9 -0
@@ -28,6 +28,9 @@ export type MessageKey =
2828 | "ai.searchPlaceholder"
2929 | "ai.scrollToLatest"
3030 | "ai.newMessages"
31+ | "ai.newChat"
32+ | "ai.chats"
33+ | "ai.noChats"
3134 | "ai.noSearchResults"
3235 | "nav.today"
3336 | "nav.classes"
@@ -1915,6 +1918,9 @@ const en: Dict = {
19151918 "ai.searchPlaceholder": "Search this chat...",
19161919 "ai.scrollToLatest": "Latest",
19171920 "ai.newMessages": "New message",
1921+ "ai.newChat": "New chat",
1922+ "ai.chats": "Chats",
1923+ "ai.noChats": "No chats yet. Start one and it will appear here.",
19181924 "ai.noSearchResults": "No messages match your search.",
19191925 "nav.today": "Today",
19201926 "nav.classes": "Courses",
@@ -3813,6 +3819,9 @@ const tr: Dict = {
38133819 "ai.searchPlaceholder": "Bu sohbette ara...",
38143820 "ai.scrollToLatest": "En alta git",
38153821 "ai.newMessages": "Yeni mesaj",
3822+ "ai.newChat": "Yeni sohbet",
3823+ "ai.chats": "Sohbetler",
3824+ "ai.noChats": "Henüz sohbet yok. Başlattığın sohbetler burada görünür.",
38163825 "ai.noSearchResults": "Aramanla eşleşen mesaj yok.",
38173826 "nav.today": "Bugün",
38183827 "nav.classes": "Dersler",