💄 cleaner study page
Browse files at this commit078b459691672e7fa5486c42cc6dbdfd08054cf5Parent: e726e76- style
- 💄 cleaner study page
4 changed files +63 -14
- src/components/rag/rag-composer.tsx +3 -3
- src/components/rag/rag-study-panel.tsx +38 -9
- src/components/rag/rag-study-welcome.tsx +14 -0
- src/components/rag/rag-thread-list.tsx +8 -2
src/components/rag/rag-composer.tsxmodified+3 -3
| @@ -29,13 +29,13 @@ export function RagComposer(props: { | |||
| 29 | 29 | ||
| 30 | return ( | 30 | return ( |
| 31 | <form | 31 | <form |
| 32 | - class="border-t border-border/70 bg-surface-base px-4 py-3" | 32 | + class="border-t border-border/70 bg-surface-base px-4 py-3 sm:px-6" |
| 33 | onSubmit={(event) => { | 33 | onSubmit={(event) => { |
| 34 | event.preventDefault(); | 34 | event.preventDefault(); |
| 35 | if (!props.disabled) props.onSubmit(); | 35 | if (!props.disabled) props.onSubmit(); |
| 36 | }} | 36 | }} |
| 37 | > | 37 | > |
| 38 | - <div class="flex items-end gap-2 rounded-xl border border-border bg-background px-3 py-2 transition-colors focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-ring"> | 38 | + <div class="mx-auto flex w-full max-w-3xl items-end gap-2 rounded-xl border border-border bg-background px-3 py-2 transition-colors focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-ring"> |
| 39 | <Textarea | 39 | <Textarea |
| 40 | ref={field} | 40 | ref={field} |
| 41 | rows={1} | 41 | rows={1} |
| @@ -63,7 +63,7 @@ export function RagComposer(props: { | |||
| 63 | <IconSend class="h-4 w-4" /> | 63 | <IconSend class="h-4 w-4" /> |
| 64 | </Button> | 64 | </Button> |
| 65 | </div> | 65 | </div> |
| 66 | - <p class="mt-1.5 px-1 text-[11px] leading-4 text-muted-foreground">{props.hint}</p> | 66 | + <p class="mx-auto mt-1.5 w-full max-w-3xl px-1 text-[11px] leading-4 text-muted-foreground">{props.hint}</p> |
| 67 | </form> | 67 | </form> |
| 68 | ); | 68 | ); |
| 69 | } | 69 | } |
src/components/rag/rag-study-panel.tsxmodified+38 -9
| @@ -1,4 +1,4 @@ | |||
| 1 | -import { For, Show, createSignal, onCleanup } from "solid-js"; | 1 | +import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js"; |
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | import type { RagMessage, RagThread } from "@/api/client"; | 3 | import type { RagMessage, RagThread } from "@/api/client"; |
| 4 | import { | 4 | import { |
| @@ -14,11 +14,12 @@ import { RagComposer } from "@/components/rag/rag-composer"; | |||
| 14 | import { ragCopy } from "@/components/rag/rag-copy"; | 14 | import { ragCopy } from "@/components/rag/rag-copy"; |
| 15 | import { RagMessageRow } from "@/components/rag/rag-message-row"; | 15 | import { RagMessageRow } from "@/components/rag/rag-message-row"; |
| 16 | import { RagStudyActions } from "@/components/rag/rag-study-actions"; | 16 | import { RagStudyActions } from "@/components/rag/rag-study-actions"; |
| 17 | +import { RagStudyWelcome } from "@/components/rag/rag-study-welcome"; | ||
| 17 | import { RagThreadList } from "@/components/rag/rag-thread-list"; | 18 | import { RagThreadList } from "@/components/rag/rag-thread-list"; |
| 18 | import { Alert } from "@/components/ui/alert"; | 19 | import { Alert } from "@/components/ui/alert"; |
| 19 | import { Button } from "@/components/ui/button"; | 20 | import { Button } from "@/components/ui/button"; |
| 20 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 21 | -import { IconEdit, IconPlus } from "@/components/ui/icons"; | 22 | +import { IconBook, IconEdit, IconPlus } from "@/components/ui/icons"; |
| 22 | import { scopeFromCitations } from "@/lib/rag-study-scope"; | 23 | import { scopeFromCitations } from "@/lib/rag-study-scope"; |
| 23 | import { usePreferences } from "@/stores/preferences-context"; | 24 | import { usePreferences } from "@/stores/preferences-context"; |
| 24 | 25 | ||
| @@ -161,6 +162,25 @@ export function RagStudyPanel() { | |||
| 161 | } | 162 | } |
| 162 | }; | 163 | }; |
| 163 | 164 | ||
| 165 | + // Follow the conversation: a new turn (or a streamed chunk) keeps the view | ||
| 166 | + // on the latest message, unless the reader has scrolled up to reread. | ||
| 167 | + let scroller: HTMLDivElement | undefined; | ||
| 168 | + createEffect( | ||
| 169 | + on( | ||
| 170 | + () => { | ||
| 171 | + const items = messages(); | ||
| 172 | + return `${items.length}:${items[items.length - 1]?.content.length ?? 0}`; | ||
| 173 | + }, | ||
| 174 | + () => { | ||
| 175 | + const el = scroller; | ||
| 176 | + if (!el) return; | ||
| 177 | + const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 160; | ||
| 178 | + if (nearBottom || sending()) queueMicrotask(() => el.scrollTo({ top: el.scrollHeight })); | ||
| 179 | + }, | ||
| 180 | + { defer: true }, | ||
| 181 | + ), | ||
| 182 | + ); | ||
| 183 | + | ||
| 164 | /** The user turn an answer replies to, used as the study range's label. */ | 184 | /** The user turn an answer replies to, used as the study range's label. */ |
| 165 | const questionBefore = (index: number) => { | 185 | const questionBefore = (index: number) => { |
| 166 | for (let i = index - 1; i >= 0; i -= 1) if (messages()[i]?.role === "user") return messages()[i]!.content; | 186 | for (let i = index - 1; i >= 0; i -= 1) if (messages()[i]?.role === "user") return messages()[i]!.content; |
| @@ -172,7 +192,7 @@ export function RagStudyPanel() { | |||
| 172 | <aside class="flex h-full min-h-0 flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-3 shadow-xs"> | 192 | <aside class="flex h-full min-h-0 flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-3 shadow-xs"> |
| 173 | <div class="flex items-center justify-between gap-2"> | 193 | <div class="flex items-center justify-between gap-2"> |
| 174 | <h2 class="text-sm font-semibold text-text-strong">{copy().history}</h2> | 194 | <h2 class="text-sm font-semibold text-text-strong">{copy().history}</h2> |
| 175 | - <Button type="button" size="sm" class="h-8 rounded-lg" onClick={newThread}> | 195 | + <Button type="button" size="sm" class="h-8 rounded-lg" disabled={!threadId() && messages().length === 0} onClick={newThread}> |
| 176 | <IconPlus class="h-4 w-4" /> | 196 | <IconPlus class="h-4 w-4" /> |
| 177 | {copy().newThread} | 197 | {copy().newThread} |
| 178 | </Button> | 198 | </Button> |
| @@ -189,10 +209,15 @@ export function RagStudyPanel() { | |||
| 189 | </aside> | 209 | </aside> |
| 190 | 210 | ||
| 191 | <section class="flex h-full min-h-0 flex-col overflow-hidden rounded-xl border border-border-line bg-surface-base shadow-xs" aria-label={copy().title}> | 211 | <section class="flex h-full min-h-0 flex-col overflow-hidden rounded-xl border border-border-line bg-surface-base shadow-xs" aria-label={copy().title}> |
| 192 | - <header class="flex shrink-0 items-center justify-between gap-3 border-b border-border-line px-4 py-3"> | 212 | + <header class="flex shrink-0 items-center justify-between gap-3 border-b border-border-line px-4 py-3 sm:px-5"> |
| 193 | - <div class="min-w-0"> | 213 | + <div class="flex min-w-0 items-center gap-3"> |
| 194 | - <p class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground">{copy().tabLabel}</p> | 214 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary-text"> |
| 195 | - <p class="truncate text-sm font-semibold text-text-strong">{activeThread()?.title || (threadId() ? copy().untitled : copy().emptyChat)}</p> | 215 | + <IconBook class="h-4 w-4" /> |
| 216 | + </span> | ||
| 217 | + <div class="min-w-0"> | ||
| 218 | + <p class="truncate text-sm font-semibold text-text-strong">{threadId() ? activeThread()?.title || copy().untitled : copy().title}</p> | ||
| 219 | + <p class="truncate text-xs text-muted-foreground">{copy().description}</p> | ||
| 220 | + </div> | ||
| 196 | </div> | 221 | </div> |
| 197 | <div class="flex shrink-0 items-center gap-2"> | 222 | <div class="flex shrink-0 items-center gap-2"> |
| 198 | <Show when={activeThread()}> | 223 | <Show when={activeThread()}> |
| @@ -204,13 +229,16 @@ export function RagStudyPanel() { | |||
| 204 | </Show> | 229 | </Show> |
| 205 | </div> | 230 | </div> |
| 206 | </header> | 231 | </header> |
| 207 | - <div class="min-h-0 flex-1 space-y-4 overflow-y-auto p-4" aria-live="polite"> | 232 | + <div ref={scroller} class="min-h-0 flex-1 overflow-y-auto px-4 py-5 sm:px-6" aria-live="polite"> |
| 233 | + <div class="mx-auto w-full max-w-3xl space-y-5"> | ||
| 208 | <Show when={error()}> | 234 | <Show when={error()}> |
| 209 | <Alert variant="destructive">{error()}</Alert> | 235 | <Alert variant="destructive">{error()}</Alert> |
| 210 | </Show> | 236 | </Show> |
| 211 | <Show | 237 | <Show |
| 212 | when={messages().length > 0} | 238 | when={messages().length > 0} |
| 213 | - fallback={<p class="py-16 text-center text-sm text-muted-foreground">{copy().emptyChatHint}</p>} | 239 | + fallback={ |
| 240 | + <RagStudyWelcome title={copy().emptyChat} hint={copy().emptyChatHint} /> | ||
| 241 | + } | ||
| 214 | > | 242 | > |
| 215 | <For each={messages()}> | 243 | <For each={messages()}> |
| 216 | {(message, index) => { | 244 | {(message, index) => { |
| @@ -239,6 +267,7 @@ export function RagStudyPanel() { | |||
| 239 | }} | 267 | }} |
| 240 | </For> | 268 | </For> |
| 241 | </Show> | 269 | </Show> |
| 270 | + </div> | ||
| 242 | </div> | 271 | </div> |
| 243 | <RagComposer | 272 | <RagComposer |
| 244 | value={draft()} | 273 | value={draft()} |
src/components/rag/rag-study-welcome.tsxadded+14 -0
| @@ -0,0 +1,14 @@ | |||
| 1 | +import { IconSparkles } from "@/components/ui/icons"; | ||
| 2 | + | ||
| 3 | +/** The Study tab before the first question: what it answers from, nothing more. */ | ||
| 4 | +export function RagStudyWelcome(props: { title: string; hint: string }) { | ||
| 5 | + return ( | ||
| 6 | + <div class="flex min-h-[40vh] flex-col items-center justify-center gap-3 py-10 text-center"> | ||
| 7 | + <span class="flex h-12 w-12 items-center justify-center rounded-2xl border border-primary/20 bg-primary/10 text-primary-text"> | ||
| 8 | + <IconSparkles class="h-6 w-6" /> | ||
| 9 | + </span> | ||
| 10 | + <h2 class="text-xl font-semibold tracking-tight text-text-strong">{props.title}</h2> | ||
| 11 | + <p class="max-w-md text-sm leading-6 text-muted-foreground">{props.hint}</p> | ||
| 12 | + </div> | ||
| 13 | + ); | ||
| 14 | +} | ||
src/components/rag/rag-thread-list.tsxmodified+8 -2
| @@ -45,10 +45,16 @@ export function RagThreadList(props: { | |||
| 45 | <ul class="space-y-1.5"> | 45 | <ul class="space-y-1.5"> |
| 46 | <For each={result().items}> | 46 | <For each={result().items}> |
| 47 | {(thread) => ( | 47 | {(thread) => ( |
| 48 | - <li class={cn("flex overflow-hidden rounded-lg border border-border", thread.id === props.activeId ? "bg-accent" : "bg-card")}> | 48 | + <li |
| 49 | + class={cn( | ||
| 50 | + "flex overflow-hidden rounded-lg border transition-colors", | ||
| 51 | + thread.id === props.activeId ? "border-primary/40 bg-primary/5" : "border-border-hairline bg-card hover:border-border-line", | ||
| 52 | + )} | ||
| 53 | + aria-current={thread.id === props.activeId ? "true" : undefined} | ||
| 54 | + > | ||
| 49 | <button | 55 | <button |
| 50 | type="button" | 56 | type="button" |
| 51 | - 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" | 57 | + 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" |
| 52 | onClick={() => props.onOpen(thread)} | 58 | onClick={() => props.onOpen(thread)} |
| 53 | > | 59 | > |
| 54 | <span class="w-full truncate text-sm font-medium">{thread.title || props.labels.untitled}</span> | 60 | <span class="w-full truncate text-sm font-medium">{thread.title || props.labels.untitled}</span> |