✨ study chat follows Mistral Vibe, chats open at their own URL
Browse files at this commit111382203a40f77d9b2aed7d1b52cc6802fea5aeParent: c923286- feat
- ✨ study chat follows Mistral Vibe, chats open at their own URL
8 changed files +350 -200
- src/components/rag/rag-composer.tsx +5 -6
- src/components/rag/rag-copy.ts +14 -0
- src/components/rag/rag-message-row.tsx +65 -49
- src/components/rag/rag-study-panel.tsx +160 -40
- src/components/rag/rag-study-welcome.tsx +7 -12
- src/components/rag/rag-thread-list.tsx +78 -92
- src/lib/format.ts +6 -0
- src/routes/router.tsx +15 -1
src/components/rag/rag-composer.tsxmodified+5 -6
| @@ -1,6 +1,6 @@ | |||
| 1 | import { createEffect, onMount } from "solid-js"; | 1 | import { createEffect, onMount } from "solid-js"; |
| 2 | import { Button } from "@/components/ui/button"; | 2 | import { Button } from "@/components/ui/button"; |
| 3 | -import { IconSend } from "@/components/ui/icons"; | 3 | +import { IconArrowUp } from "@/components/ui/icons"; |
| 4 | import { Textarea } from "@/components/ui/textarea"; | 4 | import { Textarea } from "@/components/ui/textarea"; |
| 5 | import { cn } from "@/lib/cn"; | 5 | import { cn } from "@/lib/cn"; |
| 6 | 6 | ||
| @@ -44,7 +44,7 @@ export function RagComposer(props: { | |||
| 44 | if (!props.disabled) props.onSubmit(); | 44 | if (!props.disabled) props.onSubmit(); |
| 45 | }} | 45 | }} |
| 46 | > | 46 | > |
| 47 | - <div class="mx-auto flex w-full max-w-3xl items-end gap-2 rounded-2xl border border-border bg-surface-overlay px-3.5 py-2.5 transition-colors focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-ring"> | 47 | + <div class="mx-auto flex w-full max-w-3xl items-end gap-2 rounded-2xl border border-border-line bg-surface-overlay py-2.5 pl-4 pr-2.5 shadow-xs transition-colors focus-within:border-border"> |
| 48 | <Textarea | 48 | <Textarea |
| 49 | ref={field} | 49 | ref={field} |
| 50 | rows={1} | 50 | rows={1} |
| @@ -64,16 +64,15 @@ export function RagComposer(props: { | |||
| 64 | <Button | 64 | <Button |
| 65 | type="submit" | 65 | type="submit" |
| 66 | size="sm" | 66 | size="sm" |
| 67 | - class="h-9 w-9 shrink-0 rounded-full p-0" | 67 | + class="h-9 w-9 shrink-0 rounded-lg bg-foreground p-0 text-background hover:bg-foreground/85 disabled:bg-muted disabled:text-muted-foreground disabled:opacity-100" |
| 68 | aria-label={props.sendLabel} | 68 | aria-label={props.sendLabel} |
| 69 | title={props.sendLabel} | 69 | title={props.sendLabel} |
| 70 | disabled={props.disabled || !props.value.trim()} | 70 | disabled={props.disabled || !props.value.trim()} |
| 71 | > | 71 | > |
| 72 | - <IconSend class="h-4 w-4" /> | 72 | + <IconArrowUp class="h-4 w-4" /> |
| 73 | </Button> | 73 | </Button> |
| 74 | </div> | 74 | </div> |
| 75 | - {/* Enter / Shift+Enter means nothing on a touch keyboard. */} | 75 | + <p class="mx-auto mt-2 w-full max-w-3xl px-1 text-center text-xs leading-4 text-muted-foreground">{props.hint}</p> |
| 76 | - <p class="mx-auto mt-2 w-full max-w-3xl px-1 text-center text-[11px] leading-4 text-muted-foreground [@media(pointer:coarse)]:hidden">{props.hint}</p> | ||
| 77 | </form> | 76 | </form> |
| 78 | ); | 77 | ); |
| 79 | } | 78 | } |
src/components/rag/rag-copy.tsmodified+14 -0
| @@ -19,6 +19,13 @@ const copy = { | |||
| 19 | title: "Ask your notes", | 19 | title: "Ask your notes", |
| 20 | newThread: "New chat", | 20 | newThread: "New chat", |
| 21 | history: "Chat history", | 21 | history: "Chat history", |
| 22 | + recents: "Recents", | ||
| 23 | + collapseHistory: "Hide chat history", | ||
| 24 | + expandHistory: "Show chat history", | ||
| 25 | + loadMore: "Show more", | ||
| 26 | + greetingMorning: "Good morning", | ||
| 27 | + greetingAfternoon: "Good afternoon", | ||
| 28 | + greetingEvening: "Good evening", | ||
| 22 | openHistory: "Open chat history", | 29 | openHistory: "Open chat history", |
| 23 | closeHistory: "Close chat history", | 30 | closeHistory: "Close chat history", |
| 24 | untitled: "Untitled chat", | 31 | untitled: "Untitled chat", |
| @@ -80,6 +87,13 @@ const copy = { | |||
| 80 | title: "Notlarına sor", | 87 | title: "Notlarına sor", |
| 81 | newThread: "Yeni sohbet", | 88 | newThread: "Yeni sohbet", |
| 82 | history: "Sohbet geçmişi", | 89 | history: "Sohbet geçmişi", |
| 90 | + recents: "Son sohbetler", | ||
| 91 | + collapseHistory: "Sohbet geçmişini gizle", | ||
| 92 | + expandHistory: "Sohbet geçmişini göster", | ||
| 93 | + loadMore: "Daha fazla göster", | ||
| 94 | + greetingMorning: "Günaydın", | ||
| 95 | + greetingAfternoon: "İyi günler", | ||
| 96 | + greetingEvening: "İyi akşamlar", | ||
| 83 | openHistory: "Sohbet geçmişini aç", | 97 | openHistory: "Sohbet geçmişini aç", |
| 84 | closeHistory: "Sohbet geçmişini kapat", | 98 | closeHistory: "Sohbet geçmişini kapat", |
| 85 | untitled: "Başlıksız sohbet", | 99 | untitled: "Başlıksız sohbet", |
src/components/rag/rag-message-row.tsxmodified+65 -49
| @@ -4,7 +4,9 @@ import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; | |||
| 4 | import { IconAlert, IconCopy, IconRefresh } from "@/components/ui/icons"; | 4 | import { IconAlert, IconCopy, IconRefresh } from "@/components/ui/icons"; |
| 5 | import { RagCitations } from "@/components/rag/rag-citations"; | 5 | import { RagCitations } from "@/components/rag/rag-citations"; |
| 6 | import { RagThinkingLabel } from "@/components/rag/rag-thinking-label"; | 6 | import { RagThinkingLabel } from "@/components/rag/rag-thinking-label"; |
| 7 | -import { cn } from "@/lib/cn"; | 7 | +import { LogoMark } from "@/components/brand/logo-mark"; |
| 8 | +import { formatTime } from "@/lib/format"; | ||
| 9 | +import { currentLocale } from "@/api/client"; | ||
| 8 | 10 | ||
| 9 | export function RagMessageRow(props: { | 11 | export function RagMessageRow(props: { |
| 10 | message: RagMessage; | 12 | message: RagMessage; |
| @@ -48,74 +50,88 @@ export function RagMessageRow(props: { | |||
| 48 | window.setTimeout(() => setCopied(false), 1_500); | 50 | window.setTimeout(() => setCopied(false), 1_500); |
| 49 | }; | 51 | }; |
| 50 | 52 | ||
| 53 | + const iconButton = | ||
| 54 | + "inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"; | ||
| 55 | + | ||
| 51 | return ( | 56 | return ( |
| 52 | - // The user's turn is a bubble; the answer is not. An answer is the page's | 57 | + // Vibe's turns: the question is a pill on the right; the answer runs the |
| 53 | - // content, not a message in a thread, so it runs the full reading column | 58 | + // reading column beside a small brand mark, with no frame, and its |
| 54 | - // with no frame and no avatar competing with the first line of text. | 59 | + // actions sit on one quiet icon row under it with the time at the end. |
| 55 | - <article class={cn("flex", assistant() ? "justify-start" : "justify-end")}> | 60 | + <Show |
| 56 | - <div | 61 | + when={assistant()} |
| 57 | - class={cn( | 62 | + fallback={ |
| 58 | - "text-sm", | 63 | + <article class="flex justify-end"> |
| 59 | - assistant() | 64 | + <div class="max-w-[min(36rem,85%)] whitespace-pre-wrap rounded-3xl bg-muted px-4 py-2.5 text-sm text-foreground"> |
| 60 | - ? "w-full min-w-0 text-foreground" | 65 | + {props.message.content} |
| 61 | - : "max-w-[min(46rem,88%)] rounded-xl bg-primary px-4 py-3 text-primary-foreground", | 66 | + </div> |
| 62 | - )} | 67 | + </article> |
| 63 | - > | 68 | + } |
| 64 | - <Switch> | 69 | + > |
| 65 | - <Match when={props.message.status === "pending" && !props.message.content}> | 70 | + <article class="flex gap-3"> |
| 66 | - <p class="animate-pulse text-muted-foreground" role="status"> | 71 | + <span class="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary-text" aria-hidden="true"> |
| 67 | - <RagThinkingLabel phases={[props.labels.thinking, props.labels.thinking2, props.labels.thinking3]} /> | 72 | + <LogoMark size={16} /> |
| 68 | - </p> | 73 | + </span> |
| 69 | - </Match> | 74 | + <div class="min-w-0 flex-1 text-sm text-foreground"> |
| 70 | - <Match when={props.message.status === "failed"}> | 75 | + <Switch> |
| 71 | - <div class="flex items-start gap-2 text-destructive-text"> | 76 | + <Match when={props.message.status === "pending" && !props.message.content}> |
| 72 | - <IconAlert class="mt-0.5 h-4 w-4 shrink-0" /> | 77 | + <p class="animate-pulse pt-1 text-muted-foreground" role="status"> |
| 73 | - <p>{failure()}</p> | 78 | + <RagThinkingLabel phases={[props.labels.thinking, props.labels.thinking2, props.labels.thinking3]} /> |
| 74 | - </div> | 79 | + </p> |
| 75 | - </Match> | 80 | + </Match> |
| 76 | - <Match when={props.message.abstained}> | 81 | + <Match when={props.message.status === "failed"}> |
| 77 | - <div class="space-y-1 text-muted-foreground"> | 82 | + <div class="flex items-start gap-2 pt-1 text-destructive-text"> |
| 78 | - <p>{props.message.content || props.labels.abstained}</p> | 83 | + <IconAlert class="mt-0.5 h-4 w-4 shrink-0" /> |
| 79 | - <Show when={props.message.reason}> | 84 | + <p>{failure()}</p> |
| 80 | - <p class="text-xs">{props.labels.abstainedReason(props.message.reason)}</p> | 85 | + </div> |
| 81 | - </Show> | 86 | + </Match> |
| 82 | - </div> | 87 | + <Match when={props.message.abstained}> |
| 83 | - </Match> | 88 | + <div class="space-y-1 pt-1 text-muted-foreground"> |
| 84 | - <Match when={true}> | 89 | + <p>{props.message.content || props.labels.abstained}</p> |
| 85 | - <CelebiMarkdown text={props.message.content} /> | 90 | + <Show when={props.message.reason}> |
| 86 | - </Match> | 91 | + <p class="text-xs">{props.labels.abstainedReason(props.message.reason)}</p> |
| 87 | - </Switch> | 92 | + </Show> |
| 88 | - <Show when={assistant()}> | 93 | + </div> |
| 94 | + </Match> | ||
| 95 | + <Match when={true}> | ||
| 96 | + <CelebiMarkdown text={props.message.content} /> | ||
| 97 | + </Match> | ||
| 98 | + </Switch> | ||
| 89 | <RagCitations citations={props.message.citations} labels={props.labels} /> | 99 | <RagCitations citations={props.message.citations} labels={props.labels} /> |
| 90 | {props.footer} | 100 | {props.footer} |
| 91 | - <Show when={settled() && (copyable() || props.onRetry)}> | 101 | + <Show when={settled()}> |
| 92 | - <div class="mt-2 flex flex-wrap items-center gap-3"> | 102 | + <div class="mt-2 flex items-center gap-1"> |
| 93 | <Show when={copyable()}> | 103 | <Show when={copyable()}> |
| 94 | <button | 104 | <button |
| 95 | type="button" | 105 | type="button" |
| 96 | - class="flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground" | 106 | + class={iconButton} |
| 107 | + aria-label={copied() ? props.labels.copied : props.labels.copy} | ||
| 108 | + title={copied() ? props.labels.copied : props.labels.copy} | ||
| 97 | onClick={() => void copy()} | 109 | onClick={() => void copy()} |
| 98 | > | 110 | > |
| 99 | - <IconCopy class="h-3 w-3" /> | 111 | + <IconCopy class="h-3.5 w-3.5" /> |
| 100 | - {copied() ? props.labels.copied : props.labels.copy} | ||
| 101 | </button> | 112 | </button> |
| 102 | </Show> | 113 | </Show> |
| 103 | <Show when={props.onRetry}> | 114 | <Show when={props.onRetry}> |
| 104 | {(retry) => ( | 115 | {(retry) => ( |
| 105 | <button | 116 | <button |
| 106 | type="button" | 117 | type="button" |
| 107 | - class="flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground" | 118 | + class={iconButton} |
| 119 | + aria-label={props.labels.retry} | ||
| 120 | + title={props.labels.retry} | ||
| 108 | onClick={() => retry()()} | 121 | onClick={() => retry()()} |
| 109 | > | 122 | > |
| 110 | - <IconRefresh class="h-3 w-3" /> | 123 | + <IconRefresh class="h-3.5 w-3.5" /> |
| 111 | - {props.labels.retry} | ||
| 112 | </button> | 124 | </button> |
| 113 | )} | 125 | )} |
| 114 | </Show> | 126 | </Show> |
| 127 | + <Show when={copied()}> | ||
| 128 | + <span class="text-xs text-muted-foreground" role="status">{props.labels.copied}</span> | ||
| 129 | + </Show> | ||
| 130 | + <span class="ml-auto text-xs tabular-nums text-muted-foreground">{formatTime(props.message.created_at, currentLocale())}</span> | ||
| 115 | </div> | 131 | </div> |
| 116 | </Show> | 132 | </Show> |
| 117 | - </Show> | 133 | + </div> |
| 118 | - </div> | 134 | + </article> |
| 119 | - </article> | 135 | + </Show> |
| 120 | ); | 136 | ); |
| 121 | } | 137 | } |
src/components/rag/rag-study-panel.tsxmodified+160 -40
| @@ -1,4 +1,5 @@ | |||
| 1 | import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js"; | 1 | import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js"; |
| 2 | +import { useNavigate, useParams } from "@tanstack/solid-router"; | ||
| 2 | import { formatApiError } from "@/api/client"; | 3 | import { formatApiError } from "@/api/client"; |
| 3 | import type { RagMessage, RagThread } from "@/api/client"; | 4 | import type { RagMessage, RagThread } from "@/api/client"; |
| 4 | import { | 5 | import { |
| @@ -17,15 +18,17 @@ import { RagStudyActions } from "@/components/rag/rag-study-actions"; | |||
| 17 | import { RagStudyWelcome } from "@/components/rag/rag-study-welcome"; | 18 | import { RagStudyWelcome } from "@/components/rag/rag-study-welcome"; |
| 18 | import { RagThreadList } from "@/components/rag/rag-thread-list"; | 19 | import { RagThreadList } from "@/components/rag/rag-thread-list"; |
| 19 | import { Alert } from "@/components/ui/alert"; | 20 | import { Alert } from "@/components/ui/alert"; |
| 20 | -import { Button } from "@/components/ui/button"; | ||
| 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 22 | -import { IconChevronDown, IconMenu, IconPlus, IconX } from "@/components/ui/icons"; | 22 | +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; |
| 23 | +import { IconChevronDown, IconEdit, IconMenu, IconPanelLeft, IconPlus, IconTrash, IconX } from "@/components/ui/icons"; | ||
| 23 | import { cn } from "@/lib/cn"; | 24 | import { cn } from "@/lib/cn"; |
| 24 | import { scopeFromCitations } from "@/lib/rag-study-scope"; | 25 | import { scopeFromCitations } from "@/lib/rag-study-scope"; |
| 26 | +import { useAuth } from "@/stores/auth-context"; | ||
| 25 | import { usePreferences } from "@/stores/preferences-context"; | 27 | import { usePreferences } from "@/stores/preferences-context"; |
| 26 | import { suppressQuickActions } from "@/stores/quick-actions"; | 28 | import { suppressQuickActions } from "@/stores/quick-actions"; |
| 27 | 29 | ||
| 28 | const POLL_INTERVAL_MS = 2000; | 30 | const POLL_INTERVAL_MS = 2000; |
| 31 | +const COLLAPSED_KEY = "hezarfen.study.historyCollapsed"; | ||
| 29 | 32 | ||
| 30 | /** | 33 | /** |
| 31 | * The AI hub's Study tab: chat over the course material the account may | 34 | * The AI hub's Study tab: chat over the course material the account may |
| @@ -53,6 +56,30 @@ export function RagStudyPanel() { | |||
| 53 | // on a phone keeps its conversations one tap away without spending the | 56 | // on a phone keeps its conversations one tap away without spending the |
| 54 | // screen on them. From lg it is the fixed column beside the transcript. | 57 | // screen on them. From lg it is the fixed column beside the transcript. |
| 55 | const [historyOpen, setHistoryOpen] = createSignal(false); | 58 | const [historyOpen, setHistoryOpen] = createSignal(false); |
| 59 | + // From lg the history is a sidebar the reader can fold away, remembered on | ||
| 60 | + // this device the way a chat app remembers its sidebar. | ||
| 61 | + const [historyCollapsed, setHistoryCollapsed] = createSignal( | ||
| 62 | + typeof localStorage !== "undefined" && localStorage.getItem(COLLAPSED_KEY) === "1", | ||
| 63 | + ); | ||
| 64 | + createEffect(() => { | ||
| 65 | + if (typeof localStorage !== "undefined") localStorage.setItem(COLLAPSED_KEY, historyCollapsed() ? "1" : "0"); | ||
| 66 | + }); | ||
| 67 | + const auth = useAuth(); | ||
| 68 | + // A chat lives at /ai/study/$threadId, the way Vibe opens one at | ||
| 69 | + // /chat/<id>. This panel is the persistent parent of that route, so moving | ||
| 70 | + // between chats never remounts the sidebar or cuts a streaming answer. | ||
| 71 | + const navigate = useNavigate(); | ||
| 72 | + const params = useParams({ strict: false }); | ||
| 73 | + const routeThreadId = () => (params() as { threadId?: string }).threadId; | ||
| 74 | + // The API has no single-thread read; titles come from the sidebar's list. | ||
| 75 | + const [knownThreads, setKnownThreads] = createSignal<RagThread[]>([]); | ||
| 76 | + const greeting = () => { | ||
| 77 | + const hour = new Date().getHours(); | ||
| 78 | + const base = hour < 12 ? copy().greetingMorning : hour < 18 ? copy().greetingAfternoon : copy().greetingEvening; | ||
| 79 | + const user = auth.user(); | ||
| 80 | + const name = user?.display_name?.trim() || user?.name?.trim(); | ||
| 81 | + return name ? `${base}, ${name}` : base; | ||
| 82 | + }; | ||
| 56 | createEffect(() => { | 83 | createEffect(() => { |
| 57 | if (!historyOpen()) return; | 84 | if (!historyOpen()) return; |
| 58 | const onKey = (event: KeyboardEvent) => { | 85 | const onKey = (event: KeyboardEvent) => { |
| @@ -126,19 +153,21 @@ export function RagStudyPanel() { | |||
| 126 | }; | 153 | }; |
| 127 | }; | 154 | }; |
| 128 | 155 | ||
| 129 | - const openThread = async (thread: RagThread) => { | 156 | + const loadThread = async (id: string) => { |
| 130 | stopPolling(); | 157 | stopPolling(); |
| 131 | stopStream(); | 158 | stopStream(); |
| 132 | setError(""); | 159 | setError(""); |
| 133 | - setThreadId(thread.id); | 160 | + setThreadId(id); |
| 134 | - setActiveThread(thread); | 161 | + setActiveThread(knownThreads().find((thread) => thread.id === id)); |
| 162 | + setMessages([]); | ||
| 135 | try { | 163 | try { |
| 136 | - setMessages((await getRagThreadMessages(thread.id, { limit: 500 })).items); | 164 | + const page = await getRagThreadMessages(id, { limit: 500 }); |
| 165 | + if (threadId() === id) setMessages(page.items); | ||
| 137 | } catch (err) { | 166 | } catch (err) { |
| 138 | - setError(formatApiError(err)); | 167 | + if (threadId() === id) setError(formatApiError(err)); |
| 139 | } | 168 | } |
| 140 | }; | 169 | }; |
| 141 | - const newThread = () => { | 170 | + const resetThread = () => { |
| 142 | stopPolling(); | 171 | stopPolling(); |
| 143 | stopStream(); | 172 | stopStream(); |
| 144 | setError(""); | 173 | setError(""); |
| @@ -146,6 +175,28 @@ export function RagStudyPanel() { | |||
| 146 | setActiveThread(undefined); | 175 | setActiveThread(undefined); |
| 147 | setMessages([]); | 176 | setMessages([]); |
| 148 | }; | 177 | }; |
| 178 | + // The URL is the source of truth for which chat is open. A chat this panel | ||
| 179 | + // just created is already open when its URL lands, so it is not reloaded. | ||
| 180 | + createEffect( | ||
| 181 | + on(routeThreadId, (id) => { | ||
| 182 | + if (id === threadId()) return; | ||
| 183 | + if (id) void loadThread(id); | ||
| 184 | + else resetThread(); | ||
| 185 | + }), | ||
| 186 | + ); | ||
| 187 | + createEffect(() => { | ||
| 188 | + const id = threadId(); | ||
| 189 | + if (!id || activeThread()?.id === id) return; | ||
| 190 | + const known = knownThreads().find((thread) => thread.id === id); | ||
| 191 | + if (known) setActiveThread(known); | ||
| 192 | + }); | ||
| 193 | + const openThread = (thread: RagThread) => { | ||
| 194 | + setActiveThread(thread); | ||
| 195 | + void navigate({ to: "/ai/study/$threadId", params: { threadId: thread.id } }); | ||
| 196 | + }; | ||
| 197 | + const newThread = () => { | ||
| 198 | + void navigate({ to: "/ai/study" }); | ||
| 199 | + }; | ||
| 149 | 200 | ||
| 150 | const send = async () => { | 201 | const send = async () => { |
| 151 | const content = draft().trim(); | 202 | const content = draft().trim(); |
| @@ -164,6 +215,7 @@ export function RagStudyPanel() { | |||
| 164 | const resolvedThreadId = currentThread ?? createdThread!.id; | 215 | const resolvedThreadId = currentThread ?? createdThread!.id; |
| 165 | if (createdThread) setActiveThread(createdThread); | 216 | if (createdThread) setActiveThread(createdThread); |
| 166 | setThreadId(resolvedThreadId); | 217 | setThreadId(resolvedThreadId); |
| 218 | + if (createdThread) void navigate({ to: "/ai/study/$threadId", params: { threadId: resolvedThreadId }, replace: true }); | ||
| 167 | const accepted = await postRagMessage(resolvedThreadId, content); | 219 | const accepted = await postRagMessage(resolvedThreadId, content); |
| 168 | setMessages((items) => [ | 220 | setMessages((items) => [ |
| 169 | ...items, | 221 | ...items, |
| @@ -241,7 +293,15 @@ export function RagStudyPanel() { | |||
| 241 | return ( | 293 | return ( |
| 242 | // Phones: one screen-tall column — top bar, transcript, composer — so the | 294 | // Phones: one screen-tall column — top bar, transcript, composer — so the |
| 243 | // composer sits above the tab bar instead of scrolling away with the page. | 295 | // composer sits above the tab bar instead of scrolling away with the page. |
| 244 | - <div class="grid h-[calc(var(--app-viewport)-5.5rem-max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] gap-4 max-lg:-mt-2 lg:h-[calc(100dvh-10rem)] lg:grid-cols-[18rem_minmax(0,1fr)]"> | 296 | + // From lg the page fills the content column edge to edge, below the shell |
| 297 | + // header: a flush history sidebar and the conversation beside it. | ||
| 298 | + <div | ||
| 299 | + class={cn( | ||
| 300 | + "grid h-[calc(var(--app-viewport)-5.5rem-max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] gap-4 max-lg:-mt-2", | ||
| 301 | + "lg:-mx-10 lg:-my-6 lg:h-[calc(100dvh-49px-env(safe-area-inset-top))] lg:gap-0", | ||
| 302 | + historyCollapsed() ? "lg:grid-cols-[minmax(0,1fr)]" : "lg:grid-cols-[16.5rem_minmax(0,1fr)]", | ||
| 303 | + )} | ||
| 304 | + > | ||
| 245 | <button | 305 | <button |
| 246 | type="button" | 306 | type="button" |
| 247 | tabIndex={-1} | 307 | tabIndex={-1} |
| @@ -260,43 +320,56 @@ export function RagStudyPanel() { | |||
| 260 | // slides out before it leaves the tab order. | 320 | // slides out before it leaves the tab order. |
| 261 | "fixed inset-y-0 left-0 z-[60] w-[min(20rem,85vw)] border-r border-border-line px-3 pb-[calc(max(env(safe-area-inset-bottom),var(--android-nav-inset,0px))+0.75rem)] pt-[calc(env(safe-area-inset-top)+0.75rem)] shadow-xl transition-[transform,visibility] duration-300 ease-out", | 321 | "fixed inset-y-0 left-0 z-[60] w-[min(20rem,85vw)] border-r border-border-line px-3 pb-[calc(max(env(safe-area-inset-bottom),var(--android-nav-inset,0px))+0.75rem)] pt-[calc(env(safe-area-inset-top)+0.75rem)] shadow-xl transition-[transform,visibility] duration-300 ease-out", |
| 262 | historyOpen() ? "visible translate-x-0" : "invisible -translate-x-full", | 322 | historyOpen() ? "visible translate-x-0" : "invisible -translate-x-full", |
| 263 | - "lg:visible lg:static lg:z-auto lg:h-full lg:w-auto lg:translate-x-0 lg:rounded-xl lg:border lg:p-3 lg:shadow-xs lg:transition-none", | 323 | + "lg:visible lg:static lg:z-auto lg:h-full lg:w-auto lg:translate-x-0 lg:gap-2 lg:border-r lg:border-border-hairline lg:bg-surface-overlay/40 lg:px-2 lg:py-3 lg:shadow-none lg:transition-none", |
| 324 | + historyCollapsed() && "lg:hidden", | ||
| 264 | )} | 325 | )} |
| 265 | > | 326 | > |
| 266 | - <div class="flex items-center justify-between gap-2"> | 327 | + {/* Vibe's sidebar head: the page's name, then its fold-away control. */} |
| 267 | - <h2 class="text-sm font-semibold text-text-strong">{copy().history}</h2> | 328 | + <div class="flex h-10 items-center gap-1 pl-2.5 lg:h-9"> |
| 268 | - <div class="flex items-center gap-1"> | 329 | + <h2 class="min-w-0 flex-1 truncate text-sm font-semibold text-text-strong">{copy().title}</h2> |
| 269 | - <Button | 330 | + <button |
| 270 | - type="button" | 331 | + type="button" |
| 271 | - size="sm" | 332 | + class="hidden h-8 w-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring lg:inline-flex" |
| 272 | - class="h-8 rounded-lg max-lg:h-10" | 333 | + aria-label={copy().collapseHistory} |
| 273 | - disabled={!threadId() && messages().length === 0} | 334 | + title={copy().collapseHistory} |
| 274 | - onClick={() => { | 335 | + onClick={() => setHistoryCollapsed(true)} |
| 275 | - setHistoryOpen(false); | 336 | + > |
| 276 | - newThread(); | 337 | + <IconPanelLeft class="h-4 w-4" /> |
| 277 | - }} | 338 | + </button> |
| 278 | - > | 339 | + <button |
| 279 | - <IconPlus class="h-4 w-4" /> | 340 | + type="button" |
| 280 | - {copy().newThread} | 341 | + class="inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring lg:hidden" |
| 281 | - </Button> | 342 | + aria-label={copy().closeHistory} |
| 282 | - <button | 343 | + onClick={() => setHistoryOpen(false)} |
| 283 | - type="button" | 344 | + > |
| 284 | - class="inline-flex h-10 w-10 items-center justify-center rounded-lg text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring lg:hidden" | 345 | + <IconX class="h-5 w-5" /> |
| 285 | - aria-label={copy().closeHistory} | 346 | + </button> |
| 286 | - onClick={() => setHistoryOpen(false)} | ||
| 287 | - > | ||
| 288 | - <IconX class="h-5 w-5" /> | ||
| 289 | - </button> | ||
| 290 | - </div> | ||
| 291 | </div> | 347 | </div> |
| 348 | + {/* "New chat" is a nav row, filled while the new-chat screen is open. */} | ||
| 349 | + <button | ||
| 350 | + type="button" | ||
| 351 | + class={cn( | ||
| 352 | + "flex h-10 w-full items-center gap-2.5 rounded-lg px-2.5 text-sm text-foreground outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-ring lg:h-9", | ||
| 353 | + threadId() ? "hover:bg-muted/60" : "bg-muted font-medium", | ||
| 354 | + )} | ||
| 355 | + onClick={() => { | ||
| 356 | + setHistoryOpen(false); | ||
| 357 | + newThread(); | ||
| 358 | + }} | ||
| 359 | + > | ||
| 360 | + <IconPlus class="h-4 w-4 shrink-0" /> | ||
| 361 | + <span class="truncate">{copy().newThread}</span> | ||
| 362 | + </button> | ||
| 363 | + <h3 class="px-2.5 pb-0.5 pt-4 text-xs font-medium text-muted-foreground">{copy().recents}</h3> | ||
| 292 | <RagThreadList | 364 | <RagThreadList |
| 293 | activeId={threadId()} | 365 | activeId={threadId()} |
| 294 | version={threadsVersion()} | 366 | version={threadsVersion()} |
| 295 | locale={locale()} | 367 | locale={locale()} |
| 296 | labels={copy()} | 368 | labels={copy()} |
| 369 | + onThreads={setKnownThreads} | ||
| 297 | onOpen={(thread) => { | 370 | onOpen={(thread) => { |
| 298 | setHistoryOpen(false); | 371 | setHistoryOpen(false); |
| 299 | - void openThread(thread); | 372 | + openThread(thread); |
| 300 | }} | 373 | }} |
| 301 | onRename={setRenaming} | 374 | onRename={setRenaming} |
| 302 | onRemove={setRemoving} | 375 | onRemove={setRemoving} |
| @@ -332,6 +405,53 @@ export function RagStudyPanel() { | |||
| 332 | <IconPlus class="h-5 w-5" /> | 405 | <IconPlus class="h-5 w-5" /> |
| 333 | </button> | 406 | </button> |
| 334 | </div> | 407 | </div> |
| 408 | + {/* Desktop top bar: the open chat's title and its menu; with the | ||
| 409 | + sidebar folded away, the way back to it and a fresh chat. */} | ||
| 410 | + <div class="hidden h-12 shrink-0 items-center gap-1 px-3 lg:flex"> | ||
| 411 | + <Show when={historyCollapsed()}> | ||
| 412 | + <button | ||
| 413 | + type="button" | ||
| 414 | + class="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring" | ||
| 415 | + aria-label={copy().expandHistory} | ||
| 416 | + title={copy().expandHistory} | ||
| 417 | + onClick={() => setHistoryCollapsed(false)} | ||
| 418 | + > | ||
| 419 | + <IconPanelLeft class="h-4 w-4" /> | ||
| 420 | + </button> | ||
| 421 | + <button | ||
| 422 | + type="button" | ||
| 423 | + class="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring" | ||
| 424 | + aria-label={copy().newThread} | ||
| 425 | + title={copy().newThread} | ||
| 426 | + onClick={newThread} | ||
| 427 | + > | ||
| 428 | + <IconPlus class="h-4 w-4" /> | ||
| 429 | + </button> | ||
| 430 | + </Show> | ||
| 431 | + <Show when={activeThread()}> | ||
| 432 | + {(thread) => ( | ||
| 433 | + <div class="flex min-w-0 items-center gap-1 pl-1"> | ||
| 434 | + <DropdownMenu placement="bottom-start" gutter={6}> | ||
| 435 | + <DropdownMenuTrigger class="flex min-w-0 items-center gap-1.5 rounded-lg px-2 py-1.5 text-sm font-medium text-text-strong outline-hidden transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring data-expanded:bg-muted"> | ||
| 436 | + <span class="truncate">{thread().title || copy().untitled}</span> | ||
| 437 | + <IconChevronDown class="h-3.5 w-3.5 shrink-0 opacity-60" /> | ||
| 438 | + </DropdownMenuTrigger> | ||
| 439 | + <DropdownMenuContent class="w-48"> | ||
| 440 | + <DropdownMenuItem class="gap-2.5" onSelect={() => setRenaming(thread())}> | ||
| 441 | + <IconEdit class="h-4 w-4" /> | ||
| 442 | + {copy().rename} | ||
| 443 | + </DropdownMenuItem> | ||
| 444 | + <DropdownMenuSeparator /> | ||
| 445 | + <DropdownMenuItem destructive class="gap-2.5" onSelect={() => setRemoving(thread())}> | ||
| 446 | + <IconTrash class="h-4 w-4" /> | ||
| 447 | + {copy().delete} | ||
| 448 | + </DropdownMenuItem> | ||
| 449 | + </DropdownMenuContent> | ||
| 450 | + </DropdownMenu> | ||
| 451 | + </div> | ||
| 452 | + )} | ||
| 453 | + </Show> | ||
| 454 | + </div> | ||
| 335 | <Show when={error()}> | 455 | <Show when={error()}> |
| 336 | <div class="mx-auto w-full max-w-3xl px-4 pt-1 sm:px-6"> | 456 | <div class="mx-auto w-full max-w-3xl px-4 pt-1 sm:px-6"> |
| 337 | <Alert variant="destructive">{error()}</Alert> | 457 | <Alert variant="destructive">{error()}</Alert> |
| @@ -345,13 +465,13 @@ export function RagStudyPanel() { | |||
| 345 | fallback={ | 465 | fallback={ |
| 346 | // The landing screen centres the mark and the composer instead of | 466 | // The landing screen centres the mark and the composer instead of |
| 347 | // stranding the composer at the bottom of an empty page. | 467 | // stranding the composer at the bottom of an empty page. |
| 348 | - <div class="flex min-h-[60vh] flex-col justify-center"> | 468 | + <div class="flex min-h-[60vh] flex-col justify-center lg:min-h-[calc(100dvh-16rem)]"> |
| 349 | - <RagStudyWelcome title={copy().emptyChat} hint={copy().emptyChatHint} /> | 469 | + <RagStudyWelcome title={greeting()} /> |
| 350 | <RagComposer | 470 | <RagComposer |
| 351 | value={draft()} | 471 | value={draft()} |
| 352 | placeholder={copy().placeholder} | 472 | placeholder={copy().placeholder} |
| 353 | sendLabel={copy().send} | 473 | sendLabel={copy().send} |
| 354 | - hint={copy().composerHint} | 474 | + hint={copy().emptyChatHint} |
| 355 | disabled={sending()} | 475 | disabled={sending()} |
| 356 | autofocus | 476 | autofocus |
| 357 | class="px-0 sm:px-0" | 477 | class="px-0 sm:px-0" |
| @@ -418,7 +538,7 @@ export function RagStudyPanel() { | |||
| 418 | value={draft()} | 538 | value={draft()} |
| 419 | placeholder={copy().placeholder} | 539 | placeholder={copy().placeholder} |
| 420 | sendLabel={copy().send} | 540 | sendLabel={copy().send} |
| 421 | - hint={copy().composerHint} | 541 | + hint={copy().emptyChatHint} |
| 422 | disabled={sending()} | 542 | disabled={sending()} |
| 423 | autofocus | 543 | autofocus |
| 424 | class="pb-4" | 544 | class="pb-4" |
src/components/rag/rag-study-welcome.tsxmodified+7 -12
| @@ -1,19 +1,14 @@ | |||
| 1 | -import { IconSparkles } from "@/components/ui/icons"; | 1 | +import { LogoMark } from "@/components/brand/logo-mark"; |
| 2 | 2 | ||
| 3 | /** | 3 | /** |
| 4 | - * The landing screen, which is really just the brand mark above the composer. | 4 | + * The landing screen as Vibe draws it: the brand mark and one greeting line, |
| 5 | - * The old version was a bordered illustration block that pushed the composer to | 5 | + * left-aligned on the composer's own column, right above the composer. |
| 6 | - * the bottom edge; here the mark introduces the composer and nothing else | ||
| 7 | - * competes with it — the page's whole job is "start typing". | ||
| 8 | */ | 6 | */ |
| 9 | -export function RagStudyWelcome(props: { title: string; hint: string }) { | 7 | +export function RagStudyWelcome(props: { title: string }) { |
| 10 | return ( | 8 | return ( |
| 11 | - <div class="flex flex-col items-center gap-3 pb-6 text-center"> | 9 | + <div class="flex flex-col items-start gap-4 pb-5"> |
| 12 | - <span class="flex h-11 w-11 items-center justify-center rounded-2xl bg-primary/10 text-primary-text"> | 10 | + <LogoMark size={40} /> |
| 13 | - <IconSparkles class="h-5 w-5" /> | 11 | + <h2 class="text-3xl font-medium tracking-tight text-text-strong sm:text-[2.1rem]">{props.title}</h2> |
| 14 | - </span> | ||
| 15 | - <h2 class="text-2xl font-semibold tracking-tight text-text-strong">{props.title}</h2> | ||
| 16 | - <p class="max-w-md text-sm leading-6 text-muted-foreground">{props.hint}</p> | ||
| 17 | </div> | 12 | </div> |
| 18 | ); | 13 | ); |
| 19 | } | 14 | } |
src/components/rag/rag-thread-list.tsxmodified+78 -92
| @@ -1,31 +1,18 @@ | |||
| 1 | -import { For, Show, createEffect, createSignal, on } from "solid-js"; | 1 | +import { For, Show, createEffect, createSignal } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | import { getRagThreads } from "@/api/rag"; | 3 | import { getRagThreads } from "@/api/rag"; |
| 4 | import type { RagThread } from "@/api/client"; | 4 | import type { RagThread } from "@/api/client"; |
| 5 | import { EmptyInline } from "@/components/ui/empty-inline"; | 5 | import { EmptyInline } from "@/components/ui/empty-inline"; |
| 6 | import { IconEdit, IconTrash } from "@/components/ui/icons"; | 6 | import { IconEdit, IconTrash } from "@/components/ui/icons"; |
| 7 | import { PageSpinner } from "@/components/ui/page-spinner"; | 7 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 8 | -import { TablePagination } from "@/components/ui/table-pagination"; | ||
| 9 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 8 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 10 | import { cn } from "@/lib/cn"; | 9 | import { cn } from "@/lib/cn"; |
| 11 | -import { formatDateTime } from "@/lib/format"; | ||
| 12 | import type { Locale } from "@/i18n/messages"; | 10 | import type { Locale } from "@/i18n/messages"; |
| 13 | 11 | ||
| 14 | -const THREAD_PAGE_SIZE = 12; | 12 | +// One growing page instead of numbered pages: a chat sidebar scrolls, it does |
| 15 | -const DAY_MS = 86_400_000; | 13 | +// not paginate. The API caps a page at 500 rows. |
| 16 | - | 14 | +const THREAD_PAGE_SIZE = 40; |
| 17 | -type Bucket = "today" | "yesterday" | "week" | "earlier"; | 15 | +const THREAD_PAGE_MAX = 500; |
| 18 | -const BUCKET_ORDER: Bucket[] = ["today", "yesterday", "week", "earlier"]; | ||
| 19 | - | ||
| 20 | -/** Which recency bucket a thread falls in, by local calendar day rather than a | ||
| 21 | - * rolling 24 hours — "dün" has to mean yesterday's date, not 25 hours ago. */ | ||
| 22 | -function bucketOf(updatedAt: number, now: Date): Bucket { | ||
| 23 | - const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime(); | ||
| 24 | - if (updatedAt >= startOfToday) return "today"; | ||
| 25 | - if (updatedAt >= startOfToday - DAY_MS) return "yesterday"; | ||
| 26 | - if (updatedAt >= startOfToday - 6 * DAY_MS) return "week"; | ||
| 27 | - return "earlier"; | ||
| 28 | -} | ||
| 29 | 16 | ||
| 30 | export function RagThreadList(props: { | 17 | export function RagThreadList(props: { |
| 31 | activeId?: string; | 18 | activeId?: string; |
| @@ -38,96 +25,95 @@ export function RagThreadList(props: { | |||
| 38 | rename: string; | 25 | rename: string; |
| 39 | actions: string; | 26 | actions: string; |
| 40 | delete: string; | 27 | delete: string; |
| 28 | + loadMore: string; | ||
| 41 | groupToday: string; | 29 | groupToday: string; |
| 42 | groupYesterday: string; | 30 | groupYesterday: string; |
| 43 | groupThisWeek: string; | 31 | groupThisWeek: string; |
| 44 | groupEarlier: string; | 32 | groupEarlier: string; |
| 45 | }; | 33 | }; |
| 34 | + /** Every thread the list holds, for callers that need a title by id. */ | ||
| 35 | + onThreads?: (threads: RagThread[]) => void; | ||
| 46 | onOpen: (thread: RagThread) => void; | 36 | onOpen: (thread: RagThread) => void; |
| 47 | onRename: (thread: RagThread) => void; | 37 | onRename: (thread: RagThread) => void; |
| 48 | onRemove: (thread: RagThread) => void; | 38 | onRemove: (thread: RagThread) => void; |
| 49 | }) { | 39 | }) { |
| 50 | - const [page, setPage] = createSignal(0); | 40 | + const [limit, setLimit] = createSignal(THREAD_PAGE_SIZE); |
| 51 | const [threads] = createResource( | 41 | const [threads] = createResource( |
| 52 | - () => ({ page: page(), version: props.version }), | 42 | + () => ({ limit: limit(), version: props.version }), |
| 53 | - ({ page }) => getRagThreads({ limit: THREAD_PAGE_SIZE, offset: page * THREAD_PAGE_SIZE }), | 43 | + ({ limit }) => getRagThreads({ limit, offset: 0 }), |
| 54 | ); | 44 | ); |
| 55 | - const totalPages = () => Math.max(1, Math.ceil((threads.latest?.total ?? 0) / THREAD_PAGE_SIZE)); | 45 | + createEffect(() => { |
| 56 | - const bucketLabel = (bucket: Bucket) => | 46 | + const result = threads.latest; |
| 57 | - bucket === "today" ? props.labels.groupToday | 47 | + if (result) props.onThreads?.(result.items); |
| 58 | - : bucket === "yesterday" ? props.labels.groupYesterday | 48 | + }); |
| 59 | - : bucket === "week" ? props.labels.groupThisWeek | 49 | + const hasMore = () => { |
| 60 | - : props.labels.groupEarlier; | 50 | + const result = threads.latest; |
| 61 | - // Grouping is presentational only — the page still comes from the server in | 51 | + return !!result && result.total > result.items.length && limit() < THREAD_PAGE_MAX; |
| 62 | - // its own order, so an empty bucket simply does not get a heading. | ||
| 63 | - const groups = (items: RagThread[]) => { | ||
| 64 | - const now = new Date(); | ||
| 65 | - return BUCKET_ORDER.flatMap((bucket) => { | ||
| 66 | - const rows = items.filter((thread) => bucketOf(thread.updated_at, now) === bucket); | ||
| 67 | - return rows.length > 0 ? [{ bucket, rows }] : []; | ||
| 68 | - }); | ||
| 69 | }; | 52 | }; |
| 70 | - | ||
| 71 | - createEffect(on(() => threads.latest, (result) => { | ||
| 72 | - if (result && result.items.length === 0 && page() > 0) setPage(Math.min(page() - 1, totalPages() - 1)); | ||
| 73 | - })); | ||
| 74 | - | ||
| 75 | return ( | 53 | return ( |
| 76 | - <div class="flex min-h-0 flex-1 flex-col"> | 54 | + <div class="min-h-0 flex-1 overflow-y-auto overscroll-contain"> |
| 77 | - <div class="min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1"> | 55 | + <Show when={threads.latest} fallback={<PageSpinner />}> |
| 78 | - <Show when={threads.latest} fallback={<PageSpinner />}> | 56 | + {(result) => ( |
| 79 | - {(result) => ( | 57 | + <Show |
| 80 | - <Show | 58 | + when={result().items.length > 0} |
| 81 | - when={result().items.length > 0} | 59 | + fallback={<EmptyInline class="h-full py-10" size="md" illustration="messages" title={props.labels.emptyThreads} hint={props.labels.emptyThreadsHint} />} |
| 82 | - fallback={<EmptyInline class="h-full py-10" size="md" illustration="messages" title={props.labels.emptyThreads} hint={props.labels.emptyThreadsHint} />} | 60 | + > |
| 83 | - > | 61 | + <ul class="space-y-px"> |
| 84 | - <For each={groups(result().items)}> | 62 | + <For each={result().items}> |
| 85 | - {(group) => ( | 63 | + {(thread) => { |
| 86 | - <section class="mb-3 last:mb-0"> | 64 | + const active = () => thread.id === props.activeId; |
| 87 | - <h3 class="px-1 pb-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground"> | 65 | + return ( |
| 88 | - {bucketLabel(group.bucket)} | 66 | + <li |
| 89 | - </h3> | 67 | + class={cn( |
| 90 | - <ul class="space-y-1.5"> | 68 | + "group relative flex items-center rounded-lg transition-colors", |
| 91 | - <For each={group.rows}> | 69 | + active() ? "bg-muted" : "hover:bg-muted/60", |
| 92 | - {(thread) => ( | 70 | + )} |
| 93 | - <li | 71 | + aria-current={active() ? "true" : undefined} |
| 94 | - class={cn( | 72 | + > |
| 95 | - "flex overflow-hidden rounded-lg border transition-colors", | 73 | + <button |
| 96 | - thread.id === props.activeId ? "border-primary/40 bg-primary/5" : "border-border-hairline bg-card hover:border-border-line", | 74 | + type="button" |
| 97 | - )} | 75 | + class={cn( |
| 98 | - aria-current={thread.id === props.activeId ? "true" : undefined} | 76 | + "min-w-0 flex-1 truncate rounded-lg py-1.5 pl-2.5 pr-8 text-left text-sm outline-hidden focus-visible:ring-2 focus-visible:ring-ring", |
| 99 | - > | 77 | + active() ? "font-medium text-foreground" : "text-foreground/85", |
| 100 | - <button | 78 | + )} |
| 101 | - type="button" | 79 | + title={thread.title || props.labels.untitled} |
| 102 | - 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/60" | 80 | + onClick={() => props.onOpen(thread)} |
| 103 | - onClick={() => props.onOpen(thread)} | 81 | + > |
| 104 | - > | 82 | + {thread.title || props.labels.untitled} |
| 105 | - <span class="w-full truncate text-sm font-medium">{thread.title || props.labels.untitled}</span> | 83 | + </button> |
| 106 | - <span class="text-[11px] tabular-nums text-muted-foreground">{formatDateTime(thread.updated_at, props.locale)}</span> | 84 | + {/* The row menu shows on hover, on keyboard focus and on the open chat. */} |
| 107 | - </button> | 85 | + <div |
| 108 | - <TableRowActions | 86 | + class={cn( |
| 109 | - compact | 87 | + "absolute right-1 top-1/2 -translate-y-1/2 transition-opacity focus-within:opacity-100 group-hover:opacity-100 [@media(pointer:coarse)]:opacity-100", |
| 110 | - label={props.labels.actions} | 88 | + active() ? "opacity-100" : "opacity-0", |
| 111 | - actions={[ | ||
| 112 | - { label: props.labels.rename, icon: <IconEdit class="h-4 w-4" />, onSelect: () => props.onRename(thread) }, | ||
| 113 | - { label: props.labels.delete, icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => props.onRemove(thread) }, | ||
| 114 | - ]} | ||
| 115 | - /> | ||
| 116 | - </li> | ||
| 117 | )} | 89 | )} |
| 118 | - </For> | 90 | + > |
| 119 | - </ul> | 91 | + <TableRowActions |
| 120 | - </section> | 92 | + compact |
| 121 | - )} | 93 | + label={props.labels.actions} |
| 94 | + actions={[ | ||
| 95 | + { label: props.labels.rename, icon: <IconEdit class="h-4 w-4" />, onSelect: () => props.onRename(thread) }, | ||
| 96 | + { label: props.labels.delete, icon: <IconTrash class="h-4 w-4" />, destructive: true, onSelect: () => props.onRemove(thread) }, | ||
| 97 | + ]} | ||
| 98 | + /> | ||
| 99 | + </div> | ||
| 100 | + </li> | ||
| 101 | + ); | ||
| 102 | + }} | ||
| 122 | </For> | 103 | </For> |
| 104 | + </ul> | ||
| 105 | + <Show when={hasMore()}> | ||
| 106 | + <button | ||
| 107 | + type="button" | ||
| 108 | + class="mt-1 w-full rounded-lg px-2.5 py-1.5 text-left text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-50" | ||
| 109 | + disabled={threads.loading} | ||
| 110 | + onClick={() => setLimit((value) => Math.min(THREAD_PAGE_MAX, value + THREAD_PAGE_SIZE))} | ||
| 111 | + > | ||
| 112 | + {props.labels.loadMore} | ||
| 113 | + </button> | ||
| 123 | </Show> | 114 | </Show> |
| 124 | - )} | 115 | + </Show> |
| 125 | - </Show> | 116 | + )} |
| 126 | - </div> | ||
| 127 | - <Show when={totalPages() > 1}> | ||
| 128 | - <div class="mt-3 shrink-0"> | ||
| 129 | - <TablePagination pageIndex={page()} pageCount={totalPages()} onPageChange={setPage} /> | ||
| 130 | - </div> | ||
| 131 | </Show> | 117 | </Show> |
| 132 | </div> | 118 | </div> |
| 133 | ); | 119 | ); |
src/lib/format.tsmodified+6 -0
| @@ -8,6 +8,12 @@ export function formatDateTime(ms: number | null | undefined, locale: Locale = " | |||
| 8 | }).format(new Date(ms)); | 8 | }).format(new Date(ms)); |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | +/** Time only (e.g. "07:33") — for a chat turn's stamp. */ | ||
| 12 | +export function formatTime(ms: number | null | undefined, locale: Locale = "en"): string { | ||
| 13 | + if (ms == null) return "—"; | ||
| 14 | + return new Intl.DateTimeFormat(locale === "tr" ? "tr-TR" : "en-US", { timeStyle: "short" }).format(new Date(ms)); | ||
| 15 | +} | ||
| 16 | + | ||
| 11 | /** Date only, no time — for stacked date/time cells. */ | 17 | /** Date only, no time — for stacked date/time cells. */ |
| 12 | export function formatDate(ms: number | null | undefined, locale: Locale = "en"): string { | 18 | export function formatDate(ms: number | null | undefined, locale: Locale = "en"): string { |
| 13 | if (ms == null) return "—"; | 19 | if (ms == null) return "—"; |
src/routes/router.tsxmodified+15 -1
| @@ -488,12 +488,26 @@ const aiStudioNoteRoute = createRoute({ | |||
| 488 | component: AiStudioNotePage, | 488 | component: AiStudioNotePage, |
| 489 | }); | 489 | }); |
| 490 | 490 | ||
| 491 | +// The study chat is one persistent parent (sidebar + transcript) with the | ||
| 492 | +// open chat as a child in the URL, so switching chats never remounts it. | ||
| 491 | const aiStudyRoute = createRoute({ | 493 | const aiStudyRoute = createRoute({ |
| 492 | getParentRoute: () => rootRoute, | 494 | getParentRoute: () => rootRoute, |
| 493 | path: "/ai/study", | 495 | path: "/ai/study", |
| 494 | component: AiStudyPage, | 496 | component: AiStudyPage, |
| 495 | }); | 497 | }); |
| 496 | 498 | ||
| 499 | +const aiStudyIndexRoute = createRoute({ | ||
| 500 | + getParentRoute: () => aiStudyRoute, | ||
| 501 | + path: "/", | ||
| 502 | + component: () => null, | ||
| 503 | +}); | ||
| 504 | + | ||
| 505 | +const aiStudyThreadRoute = createRoute({ | ||
| 506 | + getParentRoute: () => aiStudyRoute, | ||
| 507 | + path: "$threadId", | ||
| 508 | + component: () => null, | ||
| 509 | +}); | ||
| 510 | + | ||
| 497 | const aiInsightsRoute = createRoute({ | 511 | const aiInsightsRoute = createRoute({ |
| 498 | getParentRoute: () => rootRoute, | 512 | getParentRoute: () => rootRoute, |
| 499 | path: "/ai/insights", | 513 | path: "/ai/insights", |
| @@ -636,7 +650,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 636 | aiRoute, | 650 | aiRoute, |
| 637 | aiStudioRoute, | 651 | aiStudioRoute, |
| 638 | aiStudioNoteRoute, | 652 | aiStudioNoteRoute, |
| 639 | - aiStudyRoute, | 653 | + aiStudyRoute.addChildren([aiStudyIndexRoute, aiStudyThreadRoute]), |
| 640 | aiInsightsRoute, | 654 | aiInsightsRoute, |
| 641 | aiInsightStudentRoute, | 655 | aiInsightStudentRoute, |
| 642 | questionGenerationRoute, | 656 | questionGenerationRoute, |