From 39c877702a08e25ef75515e7d82bb7209e5711c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Tue, 15 Sep 2026 23:31:35 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20paginated=20chat=20history?= =?UTF-8?q?=20view=20in=20=C3=87elebi=20-=20replace=20the=20horizontal=20t?= =?UTF-8?q?hread=20chip=20strip=20with=20a=20Chats=20view=20that=20pages?= =?UTF-8?q?=20=20=20through=20history=20server-side=20(limit/offset,=2010?= =?UTF-8?q?=20per=20page)=20-=20header=20shows=20the=20open=20chat=20title?= =?UTF-8?q?=20with=20New=20chat=20and=20Chats=20actions=20-=20the=20chat?= =?UTF-8?q?=20stays=20mounted=20while=20history=20is=20open,=20restoring?= =?UTF-8?q?=20its=20scroll=20=20=20position=20on=20return;=20EN/TR=20copy?= =?UTF-8?q?=20for=20the=20new=20labels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/celebi-panel.tsx | 106 ++++++++++++++----- src/components/layout/celebi-thread-list.tsx | 78 ++++++++++++++ src/i18n/messages.ts | 9 ++ 3 files changed, 164 insertions(+), 29 deletions(-) create mode 100644 src/components/layout/celebi-thread-list.tsx diff --git a/src/components/layout/celebi-panel.tsx b/src/components/layout/celebi-panel.tsx index 8fd4f5b..7c1a983 100644 --- a/src/components/layout/celebi-panel.tsx +++ b/src/components/layout/celebi-panel.tsx @@ -1,4 +1,4 @@ -import { For, Match, Show, Switch, createEffect, createSignal, onCleanup, untrack } from "solid-js"; +import { For, Match, Show, Switch, createEffect, createSignal, on, onCleanup, untrack } from "solid-js"; import { useNavigate } from "@tanstack/solid-router"; import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread, type ChatbotMessage, type ChatbotThread } from "@/api/chatbot"; import { formatApiError } from "@/api/client"; @@ -6,10 +6,11 @@ import { CelebiComposer } from "@/components/layout/celebi-composer"; import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; import { CelebiReplyActions } from "@/components/layout/celebi-reply-actions"; import { CelebiThinkingLabel } from "@/components/layout/celebi-thinking-label"; +import { CelebiThreadList } from "@/components/layout/celebi-thread-list"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { DataTableSearch } from "@/components/ui/data-table-search"; import { EmptyInline } from "@/components/ui/empty-inline"; -import { IconAlert, IconBotSquare, IconChevronDown, IconCopy, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { IconAlert, IconBotSquare, IconChevronDown, IconChevronLeft, IconCopy, IconEdit, IconMessage, IconPlus } from "@/components/ui/icons"; import { SidePanel } from "@/components/ui/side-panel"; import { cn } from "@/lib/cn"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -32,7 +33,11 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean const [draft, setDraft] = createSignal(""); const [messages, setMessages] = createSignal([]); const [threadId, setThreadId] = createSignal(); - const [threads, setThreads] = createSignal([]); + const [threadTitle, setThreadTitle] = createSignal(null); + // History lives in its own view so a long list pages instead of piling up + // as chips above the transcript. + const [view, setView] = createSignal<"chat" | "threads">("chat"); + const [threadsVersion, setThreadsVersion] = createSignal(0); const [sending, setSending] = createSignal(false); const [copiedId, setCopiedId] = createSignal(); const [searchQuery, setSearchQuery] = createSignal(""); @@ -111,7 +116,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean transcript.scrollTo({ top: transcript.scrollHeight, behavior: "smooth" }); }; const handleTranscriptScroll = () => { - if (!transcript) return; + if (!transcript || view() !== "chat") return; const top = transcript.scrollTop; const distance = transcript.scrollHeight - top - transcript.clientHeight; // A shrinking transcript (search filtering) clamps scrollTop down too, but @@ -138,6 +143,18 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean requestAnimationFrame(() => { if (pinned()) pinToBottom(); }); }); + // `display: none` can drop a scroll offset, so coming back from the history + // view restores it: the bottom when pinned, else where the reader left off. + createEffect(on(view, (current, previous) => { + if (current !== "chat" || previous !== "threads") return; + const saved = lastScrollTop; + requestAnimationFrame(() => { + if (!transcript) return; + if (pinned()) pinToBottom(); + else transcript.scrollTop = lastScrollTop = saved; + }); + })); + let pollTimer: number | undefined; let stream: EventSource | undefined; @@ -146,15 +163,27 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean pollTimer = undefined; }; const stopStream = () => { stream?.close(); stream = undefined; }; - const loadThreads = async () => { try { setThreads((await getChatbotThreads({ limit: 100 })).items); } catch { /* history is non-blocking */ } }; - const openThread = async (id: string) => { stopPolling(); stopStream(); stopReveal(); setPinned(true); setUnread(false); setThreadId(id); setMessages((await getChatbotThreadMessages(id, { limit: 500 })).items); }; - const createThread = () => { stopPolling(); stopStream(); stopReveal(); setThreadId(undefined); setMessages([]); }; + // The history view refetches its page on the version bump; the header title + // of the open chat is refreshed from the newest threads, where it sits once + // it has just been written to. + const loadThreads = async () => { + setThreadsVersion((version) => version + 1); + const active = threadId(); + if (!active) return; + try { + const match = (await getChatbotThreads({ limit: 10 })).items.find((thread) => thread.id === active); + if (match && threadId() === active) setThreadTitle(match.title); + } catch { /* history is non-blocking */ } + }; + 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); }; + const createThread = () => { stopPolling(); stopStream(); stopReveal(); setSearchQuery(""); setThreadId(undefined); setThreadTitle(null); setMessages([]); }; // Rename and delete go through the shared confirm dialog, never the // browser's own prompt()/confirm() boxes. const [renaming, setRenaming] = createSignal(null); const [removing, setRemoving] = createSignal(null); const renameThread = async (thread: ChatbotThread, title: string | undefined) => { - await patchChatbotThreadById(thread.id, { title: title?.trim() || null }); + const updated = await patchChatbotThreadById(thread.id, { title: title?.trim() || null }); + if (threadId() === thread.id) setThreadTitle(updated.title); await loadThreads(); }; const removeThread = async (thread: ChatbotThread) => { @@ -162,7 +191,6 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean if (threadId() === thread.id) createThread(); await loadThreads(); }; - createEffect(() => { if (props.open) void loadThreads(); }); const failureMessage = (code: string | null) => { 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 return (
-
- - - {(thread) => ( -
- - - -
- )} -
+
+ setView("chat")}> + + {t("common.back")} + + } + > + + + + {view() === "threads" ? t("ai.chats") : threadId() ? threadTitle() || t("ai.untitledChat") : t("ai.newChat")} + + + +
+ +
+ void openThread(thread)} + onRename={setRenaming} + onRemove={setRemoving} + /> +
+
+ {/* Hidden rather than unmounted while the history is open, so going + back lands on the same scroll position and a streaming answer + keeps writing. */} +
@@ -380,6 +427,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean disabled={!draft().trim() || sending()} />
+
void; + onRename: (thread: ChatbotThread) => void; + onRemove: (thread: ChatbotThread) => void; +}) { + const t = useT(); + const { locale } = usePreferences(); + const [page, setPage] = createSignal(0); + const [threads] = createResource( + () => ({ page: page(), version: props.version }), + ({ page }) => getChatbotThreads({ limit: THREAD_PAGE_SIZE, offset: page * THREAD_PAGE_SIZE }), + ); + const totalPages = () => Math.max(1, Math.ceil((threads.latest?.total ?? 0) / THREAD_PAGE_SIZE)); + + // Deleting the last chat on the last page leaves that page empty; step back. + createEffect(on(() => threads.latest, (result) => { + if (result && result.items.length === 0 && page() > 0) setPage(Math.min(page() - 1, totalPages() - 1)); + })); + + return ( +
+
+ }> + {(result) => ( + 0} + fallback={} + > +
    + + {(thread) => ( +
  • + + + +
  • + )} +
    +
+
+ )} + +
+ 1}> +
+ +
+
+
+ ); +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 872a02c..8470e1e 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -28,6 +28,9 @@ export type MessageKey = | "ai.searchPlaceholder" | "ai.scrollToLatest" | "ai.newMessages" + | "ai.newChat" + | "ai.chats" + | "ai.noChats" | "ai.noSearchResults" | "nav.today" | "nav.classes" @@ -1915,6 +1918,9 @@ const en: Dict = { "ai.searchPlaceholder": "Search this chat...", "ai.scrollToLatest": "Latest", "ai.newMessages": "New message", + "ai.newChat": "New chat", + "ai.chats": "Chats", + "ai.noChats": "No chats yet. Start one and it will appear here.", "ai.noSearchResults": "No messages match your search.", "nav.today": "Today", "nav.classes": "Courses", @@ -3813,6 +3819,9 @@ const tr: Dict = { "ai.searchPlaceholder": "Bu sohbette ara...", "ai.scrollToLatest": "En alta git", "ai.newMessages": "Yeni mesaj", + "ai.newChat": "Yeni sohbet", + "ai.chats": "Sohbetler", + "ai.noChats": "Henüz sohbet yok. Başlattığın sohbetler burada görünür.", "ai.noSearchResults": "Aramanla eşleşen mesaj yok.", "nav.today": "Bugün", "nav.classes": "Dersler",