✨ Çelebi chat search and jump-to-latest
Browse files at this commit105e65215c0ea10e345dd762c0814aa047b83c65Parent: b411f4e- feat
- ✨ Çelebi chat search and jump-to-latest
3 changed files +49 -6
- src/components/layout/celebi-panel.tsx +38 -5
- src/components/ui/side-panel.tsx +2 -1
- src/i18n/messages.ts +9 -0
src/components/layout/celebi-panel.tsxmodified+38 -5
| @@ -7,8 +7,9 @@ import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; | |||
| 7 | import { CelebiReplyActions } from "@/components/layout/celebi-reply-actions"; | 7 | import { CelebiReplyActions } from "@/components/layout/celebi-reply-actions"; |
| 8 | import { CelebiThinkingLabel } from "@/components/layout/celebi-thinking-label"; | 8 | import { CelebiThinkingLabel } from "@/components/layout/celebi-thinking-label"; |
| 9 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 9 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 10 | +import { DataTableSearch } from "@/components/ui/data-table-search"; | ||
| 10 | import { EmptyInline } from "@/components/ui/empty-inline"; | 11 | import { EmptyInline } from "@/components/ui/empty-inline"; |
| 11 | -import { IconAlert, IconBotSquare, IconCopy, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; | 12 | +import { IconAlert, IconBotSquare, IconChevronDown, IconCopy, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; |
| 12 | import { SidePanel } from "@/components/ui/side-panel"; | 13 | import { SidePanel } from "@/components/ui/side-panel"; |
| 13 | import { cn } from "@/lib/cn"; | 14 | import { cn } from "@/lib/cn"; |
| 14 | import { usePreferences, useT } from "@/stores/preferences-context"; | 15 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| @@ -34,6 +35,8 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 34 | const [threads, setThreads] = createSignal<ChatbotThread[]>([]); | 35 | const [threads, setThreads] = createSignal<ChatbotThread[]>([]); |
| 35 | const [sending, setSending] = createSignal(false); | 36 | const [sending, setSending] = createSignal(false); |
| 36 | const [copiedId, setCopiedId] = createSignal<string>(); | 37 | const [copiedId, setCopiedId] = createSignal<string>(); |
| 38 | + const [searchQuery, setSearchQuery] = createSignal(""); | ||
| 39 | + const [showScrollToLatest, setShowScrollToLatest] = createSignal(false); | ||
| 37 | 40 | ||
| 38 | const copyMessage = async (message: PanelMessage) => { | 41 | const copyMessage = async (message: PanelMessage) => { |
| 39 | await navigator.clipboard.writeText(message.content); | 42 | await navigator.clipboard.writeText(message.content); |
| @@ -94,7 +97,18 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 94 | const NEAR_BOTTOM_PX = 64; | 97 | const NEAR_BOTTOM_PX = 64; |
| 95 | const scrollToLatest = () => { | 98 | const scrollToLatest = () => { |
| 96 | if (!transcript) return; | 99 | if (!transcript) return; |
| 97 | - transcript.scrollTop = transcript.scrollHeight; | 100 | + transcript.scrollTo({ top: transcript.scrollHeight, behavior: "smooth" }); |
| 101 | + setShowScrollToLatest(false); | ||
| 102 | + }; | ||
| 103 | + const handleTranscriptScroll = () => { | ||
| 104 | + if (!transcript) return; | ||
| 105 | + const distance = transcript.scrollHeight - transcript.scrollTop - transcript.clientHeight; | ||
| 106 | + setShowScrollToLatest(distance > NEAR_BOTTOM_PX); | ||
| 107 | + }; | ||
| 108 | + const filteredMessages = () => { | ||
| 109 | + const query = searchQuery().trim().toLocaleLowerCase(locale()); | ||
| 110 | + if (!query) return messages(); | ||
| 111 | + return messages().filter((message) => message.content.toLocaleLowerCase(locale()).includes(query)); | ||
| 98 | }; | 112 | }; |
| 99 | createEffect(() => { | 113 | createEffect(() => { |
| 100 | const items = messages(); | 114 | const items = messages(); |
| @@ -217,7 +231,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 217 | }; | 231 | }; |
| 218 | 232 | ||
| 219 | return ( | 233 | return ( |
| 220 | - <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("ai.title")} description={t("ai.description")}> | 234 | + <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("ai.title")} description={t("ai.description")} bodyClass="overflow-hidden"> |
| 221 | <div class="flex h-full min-h-0 flex-col"> | 235 | <div class="flex h-full min-h-0 flex-col"> |
| 222 | <div class="mb-3 flex shrink-0 gap-2 overflow-x-auto border-b border-border pb-3"> | 236 | <div class="mb-3 flex shrink-0 gap-2 overflow-x-auto border-b border-border pb-3"> |
| 223 | <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}> | 237 | <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}> |
| @@ -240,15 +254,33 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 240 | )} | 254 | )} |
| 241 | </For> | 255 | </For> |
| 242 | </div> | 256 | </div> |
| 243 | - <div ref={transcript} class="min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1"> | 257 | + <div class="mb-3 flex shrink-0 items-center gap-2"> |
| 258 | + <DataTableSearch value={searchQuery()} onChange={setSearchQuery} placeholder={t("ai.searchPlaceholder")} class="min-w-0 flex-1" /> | ||
| 259 | + <Show when={showScrollToLatest()}> | ||
| 260 | + <button | ||
| 261 | + type="button" | ||
| 262 | + class="inline-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 shadow-sm transition-colors hover:bg-accent" | ||
| 263 | + onClick={scrollToLatest} | ||
| 264 | + aria-label={t("ai.scrollToLatest")} | ||
| 265 | + > | ||
| 266 | + <IconChevronDown class="h-3.5 w-3.5" /> | ||
| 267 | + <span class="hidden sm:inline">{t("ai.scrollToLatest")}</span> | ||
| 268 | + </button> | ||
| 269 | + </Show> | ||
| 270 | + </div> | ||
| 271 | + <div ref={transcript} onScroll={handleTranscriptScroll} class="min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1"> | ||
| 244 | <Show | 272 | <Show |
| 245 | when={messages().length > 0} | 273 | when={messages().length > 0} |
| 246 | fallback={ | 274 | fallback={ |
| 247 | <EmptyInline class="h-full py-10" size="md" illustration="messages" title={t("ai.title")} hint={t("ai.empty")} /> | 275 | <EmptyInline class="h-full py-10" size="md" illustration="messages" title={t("ai.title")} hint={t("ai.empty")} /> |
| 248 | } | 276 | } |
| 249 | > | 277 | > |
| 278 | + <Show | ||
| 279 | + when={filteredMessages().length > 0} | ||
| 280 | + fallback={<p class="py-10 text-center text-sm text-muted-foreground">{t("ai.noSearchResults")}</p>} | ||
| 281 | + > | ||
| 250 | <div class="flex flex-col gap-3"> | 282 | <div class="flex flex-col gap-3"> |
| 251 | - <For each={messages()}> | 283 | + <For each={filteredMessages()}> |
| 252 | {(message) => ( | 284 | {(message) => ( |
| 253 | <div class={message.role === "user" ? "ml-8 rounded-lg rounded-br-sm bg-primary px-3.5 py-2.5 text-sm text-primary-foreground" : "mr-6 rounded-lg rounded-bl-sm border border-border bg-card px-3.5 py-2.5 text-sm text-foreground shadow-sm"}> | 285 | <div class={message.role === "user" ? "ml-8 rounded-lg rounded-br-sm bg-primary px-3.5 py-2.5 text-sm text-primary-foreground" : "mr-6 rounded-lg rounded-bl-sm border border-border bg-card px-3.5 py-2.5 text-sm text-foreground shadow-sm"}> |
| 254 | <Switch> | 286 | <Switch> |
| @@ -312,6 +344,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | |||
| 312 | </For> | 344 | </For> |
| 313 | </div> | 345 | </div> |
| 314 | </Show> | 346 | </Show> |
| 347 | + </Show> | ||
| 315 | </div> | 348 | </div> |
| 316 | <div class="mt-4 shrink-0"> | 349 | <div class="mt-4 shrink-0"> |
| 317 | <CelebiComposer | 350 | <CelebiComposer |
src/components/ui/side-panel.tsxmodified+2 -1
| @@ -14,6 +14,7 @@ export function SidePanel( | |||
| 14 | class?: string; | 14 | class?: string; |
| 15 | /** default ~34rem, wide ~42rem, xl ~48rem — for report tables */ | 15 | /** default ~34rem, wide ~42rem, xl ~48rem — for report tables */ |
| 16 | size?: "default" | "wide" | "xl"; | 16 | size?: "default" | "wide" | "xl"; |
| 17 | + bodyClass?: string; | ||
| 17 | }>, | 18 | }>, |
| 18 | ) { | 19 | ) { |
| 19 | // Kobalte's modal Dialog hides the app with aria-hidden before its focus | 20 | // Kobalte's modal Dialog hides the app with aria-hidden before its focus |
| @@ -74,7 +75,7 @@ export function SidePanel( | |||
| 74 | <IconX class="h-4 w-4" /> | 75 | <IconX class="h-4 w-4" /> |
| 75 | </DialogPrimitive.CloseButton> | 76 | </DialogPrimitive.CloseButton> |
| 76 | </div> | 77 | </div> |
| 77 | - <div class="side-panel-body min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-5 py-5"> | 78 | + <div class={cn("side-panel-body min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-5 py-5", props.bodyClass)}> |
| 78 | {props.children} | 79 | {props.children} |
| 79 | </div> | 80 | </div> |
| 80 | </DialogPrimitive.Content> | 81 | </DialogPrimitive.Content> |
src/i18n/messages.tsmodified+9 -0
| @@ -25,6 +25,9 @@ export type MessageKey = | |||
| 25 | | "ai.goTo" | 25 | | "ai.goTo" |
| 26 | | "ai.didYouMean" | 26 | | "ai.didYouMean" |
| 27 | | "ai.skipTyping" | 27 | | "ai.skipTyping" |
| 28 | + | "ai.searchPlaceholder" | ||
| 29 | + | "ai.scrollToLatest" | ||
| 30 | + | "ai.noSearchResults" | ||
| 28 | | "nav.today" | 31 | | "nav.today" |
| 29 | | "nav.classes" | 32 | | "nav.classes" |
| 30 | | "nav.classGroups" | 33 | | "nav.classGroups" |
| @@ -1908,6 +1911,9 @@ const en: Dict = { | |||
| 1908 | "ai.goTo": "Go to the page", | 1911 | "ai.goTo": "Go to the page", |
| 1909 | "ai.didYouMean": "Did you mean one of these?", | 1912 | "ai.didYouMean": "Did you mean one of these?", |
| 1910 | "ai.skipTyping": "Show the whole answer", | 1913 | "ai.skipTyping": "Show the whole answer", |
| 1914 | + "ai.searchPlaceholder": "Search this chat...", | ||
| 1915 | + "ai.scrollToLatest": "Latest", | ||
| 1916 | + "ai.noSearchResults": "No messages match your search.", | ||
| 1911 | "nav.today": "Today", | 1917 | "nav.today": "Today", |
| 1912 | "nav.classes": "Courses", | 1918 | "nav.classes": "Courses", |
| 1913 | "nav.classGroups": "Classes", | 1919 | "nav.classGroups": "Classes", |
| @@ -3802,6 +3808,9 @@ const tr: Dict = { | |||
| 3802 | "ai.goTo": "Sayfaya git", | 3808 | "ai.goTo": "Sayfaya git", |
| 3803 | "ai.didYouMean": "Bunu mu demek istedin?", | 3809 | "ai.didYouMean": "Bunu mu demek istedin?", |
| 3804 | "ai.skipTyping": "Cevabın tamamını göster", | 3810 | "ai.skipTyping": "Cevabın tamamını göster", |
| 3811 | + "ai.searchPlaceholder": "Bu sohbette ara...", | ||
| 3812 | + "ai.scrollToLatest": "En alta git", | ||
| 3813 | + "ai.noSearchResults": "Aramanla eşleşen mesaj yok.", | ||
| 3805 | "nav.today": "Bugün", | 3814 | "nav.today": "Bugün", |
| 3806 | "nav.classes": "Dersler", | 3815 | "nav.classes": "Dersler", |
| 3807 | "nav.classGroups": "Şubeler", | 3816 | "nav.classGroups": "Şubeler", |