📱 theme the system chrome, keep typed text readable, stop false save errors
Browse files at this commit4d56b039cfbfefe32e2fd125411709f0db04afbaParent: a6408c3- fix
- 📱 theme the system chrome, keep typed text readable, stop false save errors
10 changed files +183 -31
- index.html +17 -1
- src/components/layout/celebi-composer.tsx +9 -2
- src/components/layout/celebi-panel.tsx +41 -4
- src/components/layout/command-palette.tsx +11 -2
- src/components/ui/dialog.tsx +1 -1
- src/components/ui/side-panel.tsx +1 -1
- src/index.css +39 -1
- src/pages/class-detail-page.tsx +43 -18
- src/pages/classes-page.tsx +8 -1
- src/stores/preferences-context.tsx +13 -0
index.htmlmodified+17 -1
| @@ -2,8 +2,19 @@ | ||
| 2 | 2 | <html lang="en"> |
| 3 | 3 | <head> |
| 4 | 4 | <meta charset="UTF-8" /> |
| 5 | - <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" /> | |
| 5 | + <!-- interactive-widget=resizes-content: with the default the soft keyboard | |
| 6 | + only shrinks the visual viewport, so a fixed panel keeps its full | |
| 7 | + height and its composer stays behind the keys. Resizing the layout | |
| 8 | + viewport instead makes 100dvh and fixed insets follow the keyboard, | |
| 9 | + which keeps the field the user is typing in on screen. --> | |
| 10 | + <meta | |
| 11 | + name="viewport" | |
| 12 | + content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content" | |
| 13 | + /> | |
| 6 | 14 | <meta name="color-scheme" content="light dark" /> |
| 15 | + <!-- Repainted from --background by preferences-context on every theme | |
| 16 | + change; this literal is only the value the first paint uses. --> | |
| 17 | + <meta name="theme-color" content="#fafafa" /> | |
| 7 | 18 | <meta |
| 8 | 19 | name="description" |
| 9 | 20 | content="Hezarfen; eğitim, ders, sınav, ödev, takvim ve kampüs işlemlerini tek yerde yöneten güvenli öğrenme platformudur." |
| @@ -20,6 +31,11 @@ | ||
| 20 | 31 | (theme !== "light" && window.matchMedia("(prefers-color-scheme: dark)").matches); |
| 21 | 32 | document.documentElement.setAttribute("data-kb-theme", dark ? "dark" : "light"); |
| 22 | 33 | if (dark) document.documentElement.classList.add("dark"); |
| 34 | + // The stylesheet has not loaded yet, so these repeat --background / | |
| 35 | + // --background(dark) as literals. Keep them in step with index.css. | |
| 36 | + document.documentElement.style.backgroundColor = dark ? "#0a0a0a" : "#fafafa"; | |
| 37 | + const themeColor = document.querySelector('meta[name="theme-color"]'); | |
| 38 | + if (themeColor) themeColor.setAttribute("content", dark ? "#0a0a0a" : "#fafafa"); | |
| 23 | 39 | const locale = localStorage.getItem("hezarfen.locale"); |
| 24 | 40 | if (locale === "en" || locale === "tr") document.documentElement.lang = locale; |
| 25 | 41 | // Android reports only the display cutout through CSS env(), so the |
src/components/layout/celebi-composer.tsxmodified+9 -2
| @@ -35,9 +35,16 @@ export function CelebiComposer(props: { | ||
| 35 | 35 | props.onSubmit(); |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | + // The strip has to be opaque rather than a gradient fading into the panel: | |
| 39 | + // on a phone the messages scroll right up to it, and a half-transparent band | |
| 40 | + // let the last line show through the field's own row. | |
| 41 | + // | |
| 42 | + // The field itself is transparent over the card, so it names its text and | |
| 43 | + // caret colors: a control that drops its background inherits neither, and | |
| 44 | + // the draft came out unreadable once focused. | |
| 38 | 45 | return ( |
| 39 | 46 | <form |
| 40 | - class="sticky bottom-0 -mx-5 bg-gradient-to-t from-background via-background to-transparent px-5 pb-1 pt-3 sm:-mx-6 sm:px-6" | |
| 47 | + class="sticky bottom-0 -mx-5 border-t border-border/60 bg-background px-5 pb-1 pt-3 sm:-mx-6 sm:px-6" | |
| 41 | 48 | onSubmit={(event) => { |
| 42 | 49 | event.preventDefault(); |
| 43 | 50 | submit(); |
| @@ -47,7 +54,7 @@ export function CelebiComposer(props: { | ||
| 47 | 54 | <Textarea |
| 48 | 55 | ref={field} |
| 49 | 56 | rows={1} |
| 50 | - class="max-h-40 min-h-0 flex-1 resize-none overflow-y-auto border-0 bg-transparent px-0 py-1.5 shadow-none hover:border-0 hover:bg-transparent focus:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0" | |
| 57 | + class="max-h-40 min-h-0 flex-1 resize-none overflow-y-auto border-0 bg-transparent px-0 py-1.5 text-card-foreground caret-primary shadow-none hover:border-0 hover:bg-transparent focus:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0" | |
| 51 | 58 | value={props.value} |
| 52 | 59 | placeholder={t("ai.placeholder")} |
| 53 | 60 | onInput={(event) => props.onInput(event.currentTarget.value)} |
src/components/layout/celebi-panel.tsxmodified+41 -4
| @@ -5,8 +5,9 @@ import { CelebiComposer } from "@/components/layout/celebi-composer"; | ||
| 5 | 5 | import { CelebiMarkdown } from "@/components/layout/celebi-markdown"; |
| 6 | 6 | import { CelebiSuggestions } from "@/components/layout/celebi-suggestions"; |
| 7 | 7 | import { CelebiThinkingLabel } from "@/components/layout/celebi-thinking-label"; |
| 8 | -import { IconAlert, IconBotSquare, IconCopy, IconSparkles } from "@/components/ui/icons"; | |
| 8 | +import { IconAlert, IconBotSquare, IconCopy, IconEdit, IconPlus, IconSparkles, IconTrash } from "@/components/ui/icons"; | |
| 9 | 9 | import { SidePanel } from "@/components/ui/side-panel"; |
| 10 | +import { cn } from "@/lib/cn"; | |
| 10 | 11 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 11 | 12 | |
| 12 | 13 | type PanelMessage = Pick<ChatbotMessage, "id" | "role" | "status" | "content" | "truncated" | "error_code">; |
| @@ -29,6 +30,25 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | ||
| 29 | 30 | window.setTimeout(() => setCopiedId((current) => (current === message.id ? undefined : current)), 1_500); |
| 30 | 31 | }; |
| 31 | 32 | |
| 33 | + // The transcript follows the newest message, but only while the reader is | |
| 34 | + // already at the bottom: scrolling up to re-read an earlier answer must not | |
| 35 | + // be yanked back down by the next streamed chunk. | |
| 36 | + let transcript: HTMLDivElement | undefined; | |
| 37 | + const NEAR_BOTTOM_PX = 64; | |
| 38 | + const scrollToLatest = () => { | |
| 39 | + if (!transcript) return; | |
| 40 | + transcript.scrollTop = transcript.scrollHeight; | |
| 41 | + }; | |
| 42 | + createEffect(() => { | |
| 43 | + const items = messages(); | |
| 44 | + if (!transcript || items.length === 0) return; | |
| 45 | + const distance = transcript.scrollHeight - transcript.scrollTop - transcript.clientHeight; | |
| 46 | + const atBottom = distance <= NEAR_BOTTOM_PX; | |
| 47 | + // The DOM node for the message that just arrived is written after this | |
| 48 | + // effect reads the store, so the scroll waits for the next frame. | |
| 49 | + if (atBottom) requestAnimationFrame(scrollToLatest); | |
| 50 | + }); | |
| 51 | + | |
| 32 | 52 | let pollTimer: number | undefined; |
| 33 | 53 | let stream: EventSource | undefined; |
| 34 | 54 | |
| @@ -130,10 +150,27 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean | ||
| 130 | 150 | <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("ai.title")} description={t("ai.description")}> |
| 131 | 151 | <div class="flex h-full min-h-0 flex-col"> |
| 132 | 152 | <div class="mb-3 flex shrink-0 gap-2 overflow-x-auto border-b border-border pb-3"> |
| 133 | - <button type="button" class="rounded-lg border px-2.5 py-1.5 text-xs font-medium" onClick={createThread}>{locale() === "tr" ? "Yeni sohbet" : "New chat"}</button> | |
| 134 | - <For each={threads()}>{(thread) => <div class="flex shrink-0 overflow-hidden rounded-lg border"><button type="button" class={thread.id === threadId() ? "bg-muted px-2.5 py-1.5 text-xs font-medium" : "px-2.5 py-1.5 text-xs"} onClick={() => void openThread(thread.id)}>{thread.title || (locale() === "tr" ? "Adsız sohbet" : "Untitled chat")}</button><button type="button" class="border-l px-2 text-xs" aria-label={locale() === "tr" ? "Sohbeti yeniden adlandır" : "Rename chat"} onClick={() => void renameThread(thread)}>✎</button><button type="button" class="border-l px-2 text-xs text-destructive" aria-label={locale() === "tr" ? "Sohbeti sil" : "Delete chat"} onClick={() => void removeThread(thread)}>×</button></div>}</For> | |
| 153 | + <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}> | |
| 154 | + <IconPlus class="h-3.5 w-3.5" /> | |
| 155 | + {locale() === "tr" ? "Yeni sohbet" : "New chat"} | |
| 156 | + </button> | |
| 157 | + <For each={threads()}> | |
| 158 | + {(thread) => ( | |
| 159 | + <div class={cn("flex h-8 shrink-0 items-center overflow-hidden rounded-lg border border-border", thread.id === threadId() ? "bg-accent" : "bg-card")}> | |
| 160 | + <button type="button" class="max-w-[10rem] truncate px-2.5 text-xs text-foreground" onClick={() => void openThread(thread.id)}> | |
| 161 | + {thread.title || (locale() === "tr" ? "Adsız sohbet" : "Untitled chat")} | |
| 162 | + </button> | |
| 163 | + <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={() => void renameThread(thread)}> | |
| 164 | + <IconEdit class="h-3.5 w-3.5" /> | |
| 165 | + </button> | |
| 166 | + <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={() => void removeThread(thread)}> | |
| 167 | + <IconTrash class="h-3.5 w-3.5" /> | |
| 168 | + </button> | |
| 169 | + </div> | |
| 170 | + )} | |
| 171 | + </For> | |
| 135 | 172 | </div> |
| 136 | - <div class="min-h-0 flex-1 overflow-y-auto pr-1"> | |
| 173 | + <div ref={transcript} class="min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1"> | |
| 137 | 174 | <Show |
| 138 | 175 | when={messages().length > 0} |
| 139 | 176 | fallback={ |
src/components/layout/command-palette.tsxmodified+11 -2
| @@ -308,7 +308,6 @@ export function CommandPalette(props: CommandPaletteProps) { | ||
| 308 | 308 | if (!props.open) return; |
| 309 | 309 | setQuery(""); |
| 310 | 310 | setSelectedIndex(0); |
| 311 | - queueMicrotask(() => inputRef?.focus()); | |
| 312 | 311 | }); |
| 313 | 312 | |
| 314 | 313 | // Reset selected index when query changes |
| @@ -358,7 +357,17 @@ export function CommandPalette(props: CommandPaletteProps) { | ||
| 358 | 357 | |
| 359 | 358 | return ( |
| 360 | 359 | <Dialog open={props.open} onOpenChange={props.onOpenChange}> |
| 361 | - <DialogContent class="max-h-[min(85vh,38rem)] max-w-2xl overflow-hidden rounded-lg p-0 shadow-2xl border border-black/8 dark:border-white/12 bg-popover/95"> | |
| 360 | + <DialogContent | |
| 361 | + class="max-h-[min(85vh,38rem)] max-w-2xl overflow-hidden rounded-lg p-0 shadow-2xl border border-black/8 dark:border-white/12 bg-popover/95" | |
| 362 | + // The dialog's focus trap parks focus on the panel itself when it | |
| 363 | + // opens, which used to swallow a focus() queued from an effect — the | |
| 364 | + // palette opened with nothing focused and the first keystroke went | |
| 365 | + // nowhere. Taking the initial focus over hands it to the query field. | |
| 366 | + onOpenAutoFocus={(event) => { | |
| 367 | + event.preventDefault(); | |
| 368 | + inputRef?.focus(); | |
| 369 | + }} | |
| 370 | + > | |
| 362 | 371 | <DialogTitle class="sr-only">{t("dashboard.commandCenter")}</DialogTitle> |
| 363 | 372 | <DialogDescription class="sr-only">{t("common.searchPlaceholder")}</DialogDescription> |
| 364 | 373 |
src/components/ui/dialog.tsxmodified+1 -1
| @@ -54,7 +54,7 @@ export function DialogHeader(props: ParentProps<{ class?: string }>) { | ||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | export function DialogBody(props: ParentProps<{ class?: string }>) { |
| 57 | - return <div class={cn("overflow-y-auto px-5 py-4 sm:px-6", props.class)}>{props.children}</div>; | |
| 57 | + return <div class={cn("overflow-y-auto overscroll-contain px-5 py-4 sm:px-6", props.class)}>{props.children}</div>; | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | export function DialogTitle<T extends ValidComponent = "h2">( |
src/components/ui/side-panel.tsxmodified+1 -1
| @@ -69,7 +69,7 @@ export function SidePanel( | ||
| 69 | 69 | <IconX class="h-4 w-4" /> |
| 70 | 70 | </DialogPrimitive.CloseButton> |
| 71 | 71 | </div> |
| 72 | - <div class="side-panel-body min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-5 py-5"> | |
| 72 | + <div class="side-panel-body min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-5 py-5"> | |
| 73 | 73 | {props.children} |
| 74 | 74 | </div> |
| 75 | 75 | </DialogPrimitive.Content> |
src/index.cssmodified+39 -1
| @@ -333,6 +333,13 @@ | ||
| 333 | 333 | instead of the viewport, which on mobile is taller than the page. */ |
| 334 | 334 | --app-viewport: calc(100dvh - env(safe-area-inset-top)); |
| 335 | 335 | |
| 336 | + /* The UA paints the caret, the text-selection handles, the keyboard and | |
| 337 | + the overscroll canvas from this — and `light dark` in the meta tag makes | |
| 338 | + it follow the OS, not the app. A dark app on a light phone then drew a | |
| 339 | + black caret on a black field, and the strip revealed by overscrolling | |
| 340 | + came back white. Pinning it per theme keeps that chrome in the theme. */ | |
| 341 | + color-scheme: light; | |
| 342 | + | |
| 336 | 343 | /* --accent-light / --accent-light-fg are set inline by preferences-context |
| 337 | 344 | when the user picks an accent color; the fallback here is the neutral |
| 338 | 345 | default for everyone else. */ |
| @@ -369,6 +376,7 @@ | ||
| 369 | 376 | /* --accent-dark / --accent-dark-fg are set inline by preferences-context — |
| 370 | 377 | a separate, lighter-lightness variant of the same picked hue so it stays |
| 371 | 378 | legible against this theme's near-black background. */ |
| 379 | + color-scheme: dark; | |
| 372 | 380 | --ui-accent: var(--accent-dark, 0 0% 92%); |
| 373 | 381 | --background: 0 0% 4%; |
| 374 | 382 | --foreground: 0 0% 98%; |
| @@ -402,7 +410,11 @@ | ||
| 402 | 410 | } |
| 403 | 411 | |
| 404 | 412 | html { |
| 405 | - @apply scroll-smooth; | |
| 413 | + @apply scroll-smooth bg-background; | |
| 414 | + /* The canvas behind the page — what an overscroll bounce or a keyboard | |
| 415 | + teardown reveals below the last element — is painted from `html`, not | |
| 416 | + from `body`. Without this it falls back to the UA's white. */ | |
| 417 | + overscroll-behavior-y: none; | |
| 406 | 418 | font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; |
| 407 | 419 | -webkit-font-smoothing: antialiased; |
| 408 | 420 | -moz-osx-font-smoothing: grayscale; |
| @@ -440,6 +452,32 @@ | ||
| 440 | 452 | pointer-events: none; |
| 441 | 453 | } |
| 442 | 454 | |
| 455 | + /* Form controls inherit `color` from Tailwind's preflight, but the caret and | |
| 456 | + the selection highlight do not follow it, and a field that overrides its | |
| 457 | + own background (the Çelebi composer is transparent on a card) could end up | |
| 458 | + with a caret the same color as what is behind it. Naming all three keeps a | |
| 459 | + focused field readable in either theme. */ | |
| 460 | + input, | |
| 461 | + textarea, | |
| 462 | + select { | |
| 463 | + color: hsl(var(--foreground)); | |
| 464 | + caret-color: hsl(var(--primary)); | |
| 465 | + -webkit-text-fill-color: currentColor; | |
| 466 | + } | |
| 467 | + | |
| 468 | + /* `-webkit-text-fill-color` inherits as a resolved color, so without this the | |
| 469 | + field's own fill would repaint the placeholder in the text color. */ | |
| 470 | + input::placeholder, | |
| 471 | + textarea::placeholder { | |
| 472 | + -webkit-text-fill-color: currentColor; | |
| 473 | + } | |
| 474 | + | |
| 475 | + input::selection, | |
| 476 | + textarea::selection { | |
| 477 | + background: hsl(var(--primary) / 0.3); | |
| 478 | + color: hsl(var(--foreground)); | |
| 479 | + } | |
| 480 | + | |
| 443 | 481 | /* Keep scrolling available while removing native scrollbar chrome globally. */ |
| 444 | 482 | * { |
| 445 | 483 | -ms-overflow-style: none; |
src/pages/class-detail-page.tsxmodified+43 -18
| @@ -1,4 +1,4 @@ | ||
| 1 | -import { For, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; | |
| 1 | +import { For, Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; | |
| 2 | 2 | import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; |
| 3 | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | 4 | import { |
| @@ -16,7 +16,7 @@ import { | ||
| 16 | 16 | import { getCourses } from "@/api/courses"; |
| 17 | 17 | import { getTerms } from "@/api/terms"; |
| 18 | 18 | import { getLimits } from "@/api/limits"; |
| 19 | -import { ApiError, formatApiError, type BlueprintSkip, type ClassCourse, type ClassMember } from "@/api/client"; | |
| 19 | +import { ApiError, formatApiError, type BlueprintSkip, type ClassCourse, type ClassGroup, type ClassMember } from "@/api/client"; | |
| 20 | 20 | import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report"; |
| 21 | 21 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 22 | 22 | import { Alert } from "@/components/ui/alert"; |
| @@ -79,11 +79,32 @@ function ClassDetailContent() { | ||
| 79 | 79 | const [members, { refetch: refetchMembers }] = createResource(id, async (classId) => (await getClassMembers(classId, { limit: 200 })).items); |
| 80 | 80 | const [classCourses, { refetch: refetchCourses }] = createResource(id, async (classId) => (await getClassCourses(classId, { limit: 50 })).items); |
| 81 | 81 | |
| 82 | + // The last class the page actually loaded. A refetch that fails leaves the | |
| 83 | + // resource in an error state, and reading it there throws; holding the last | |
| 84 | + // good value lets the page stay up and keeps the error screen for the case | |
| 85 | + // it is meant for — a first load that never produced a class. | |
| 86 | + const [loadedClass, setLoadedClass] = createSignal<ClassGroup>(); | |
| 87 | + createEffect(() => { | |
| 88 | + if (cls.state === "ready") setLoadedClass(cls()); | |
| 89 | + }); | |
| 90 | + | |
| 82 | 91 | const termName = (tid: string | null) => terms.latest?.find((term) => term.id === tid)?.name ?? (tid || t("terms.unassigned")); |
| 83 | 92 | const courseTitle = (courseId: string) => courses.latest?.find((course) => course.id === courseId)?.title ?? courseId; |
| 84 | 93 | const memberUserIds = () => (members.latest ?? []).map((row) => row.user.id); |
| 85 | 94 | const attachedCourseIds = () => (classCourses.latest ?? []).map((row) => row.course); |
| 86 | 95 | |
| 96 | + // Refreshing the tables after a successful write is not part of the write: | |
| 97 | + // a failed refetch used to be reported as if the save itself had failed, so | |
| 98 | + // the row appeared and an error banner appeared with it. The resource keeps | |
| 99 | + // its previous value and the next load picks the change up. | |
| 100 | + const refresh = async (run: () => unknown) => { | |
| 101 | + try { | |
| 102 | + await run(); | |
| 103 | + } catch { | |
| 104 | + // Stale rows are better than telling the user a save failed. | |
| 105 | + } | |
| 106 | + }; | |
| 107 | + | |
| 87 | 108 | const wrap = async (fn: () => Promise<void>, successKey?: string) => { |
| 88 | 109 | setError(""); |
| 89 | 110 | setPending(true); |
| @@ -105,7 +126,7 @@ function ClassDetailContent() { | ||
| 105 | 126 | setPending(true); |
| 106 | 127 | try { |
| 107 | 128 | const result = await postClassBlueprintApply(id()); |
| 108 | - await refetchCourses(); | |
| 129 | + await refresh(refetchCourses); | |
| 109 | 130 | setSkipped(result.skipped); |
| 110 | 131 | if (result.skipped.length === 0) setFlash(t("classBlueprints.applied")); |
| 111 | 132 | } catch (err) { |
| @@ -184,10 +205,18 @@ function ClassDetailContent() { | ||
| 184 | 205 | ]); |
| 185 | 206 | |
| 186 | 207 | return ( |
| 187 | - <Suspense fallback={<PageSpinner />}> | |
| 188 | - <Show when={cls.error} fallback={ | |
| 189 | - <Show when={cls()}> | |
| 190 | - {(c) => ( | |
| 208 | + // Only a load that never produced a class becomes the error screen. A | |
| 209 | + // refetch that fails after a save still has the class in hand, and | |
| 210 | + // replacing the whole page there read as if the save had failed. | |
| 211 | + <Show | |
| 212 | + when={loadedClass()} | |
| 213 | + fallback={ | |
| 214 | + <Show when={cls.error} fallback={<PageSpinner />}> | |
| 215 | + <Alert variant="destructive">{formatApiError(cls.error)}</Alert> | |
| 216 | + </Show> | |
| 217 | + } | |
| 218 | + > | |
| 219 | + {(c) => ( | |
| 191 | 220 | <div class="space-y-5"> |
| 192 | 221 | <Link to="/management/classes" class="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground"> |
| 193 | 222 | <IconChevronLeft class="h-4 w-4" />{t("classGroups.title")} |
| @@ -269,7 +298,7 @@ function ClassDetailContent() { | ||
| 269 | 298 | |
| 270 | 299 | {/* Edit class */} |
| 271 | 300 | <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().name}> |
| 272 | - <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { await patchClassById(id(), { name: name().trim(), grade: grade().trim() || null, term_id: termId() || null, teacher_id: teacherId() || null }); setEditing(false); await refetchClass(); }, "common.saved"); }}> | |
| 301 | + <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { await patchClassById(id(), { name: name().trim(), grade: grade().trim() || null, term_id: termId() || null, teacher_id: teacherId() || null }); setEditing(false); await refresh(refetchClass); }, "common.saved"); }}> | |
| 273 | 302 | <div class="space-y-3"> |
| 274 | 303 | <div class="space-y-1.5"><Label for="edit-class-name">{t("classGroups.className")}</Label><Input id="edit-class-name" maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div> |
| 275 | 304 | <div class="space-y-1.5"><Label for="edit-class-grade">{t("classGroups.grade")}</Label><Input id="edit-class-grade" maxlength={limits.latest?.course.max_class_grade_len} value={grade()} onInput={(e) => setGrade(e.currentTarget.value)} /></div> |
| @@ -282,7 +311,7 @@ function ClassDetailContent() { | ||
| 282 | 311 | |
| 283 | 312 | {/* Add student */} |
| 284 | 313 | <SidePanel open={showAddMember()} onOpenChange={setShowAddMember} title={t("classGroups.addStudent")} description={t("classGroups.addStudentHelp")}> |
| 285 | - <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { const uid = addUserId().trim(); if (!uid) return; await postClassMember(id(), { user_id: uid }); setAddUserId(""); setShowAddMember(false); await refetchMembers(); }, "common.saved"); }}> | |
| 314 | + <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); if (!addUserId().trim()) return; void wrap(async () => { await postClassMember(id(), { user_id: addUserId().trim() }); setAddUserId(""); setShowAddMember(false); await refresh(refetchMembers); }, "common.saved"); }}> | |
| 286 | 315 | <UserSearchSelect id="class-add-student" role="student" value={addUserId()} excludeIds={memberUserIds()} placeholder={t("form.selectStudent")} onChange={setAddUserId} /> |
| 287 | 316 | <div class="flex gap-2"><Button type="submit" disabled={pending()}>{t("classGroups.addStudent")}</Button><Button type="button" variant="outline" onClick={() => setShowAddMember(false)}>{t("common.cancel")}</Button></div> |
| 288 | 317 | </form> |
| @@ -290,7 +319,7 @@ function ClassDetailContent() { | ||
| 290 | 319 | |
| 291 | 320 | {/* Attach course */} |
| 292 | 321 | <SidePanel open={showAttachCourse()} onOpenChange={setShowAttachCourse} title={t("classGroups.attachCourse")} description={t("classGroups.attachCourseHelp")}> |
| 293 | - <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { const cid = attachCourseId(); if (!cid) return; await postClassCourse(id(), { course_id: cid }); setAttachCourseId(""); setShowAttachCourse(false); await refetchCourses(); }, "common.saved"); }}> | |
| 322 | + <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); const cid = attachCourseId(); if (!cid) return; void wrap(async () => { await postClassCourse(id(), { course_id: cid }); setAttachCourseId(""); setShowAttachCourse(false); await refresh(refetchCourses); }, "common.saved"); }}> | |
| 294 | 323 | <div class="space-y-1.5"> |
| 295 | 324 | <Label for="class-attach-course">{t("classGroups.selectCourse")}</Label> |
| 296 | 325 | <Select id="class-attach-course" value={attachCourseId()} onChange={(e) => setAttachCourseId(e.currentTarget.value)}> |
| @@ -319,7 +348,7 @@ function ClassDetailContent() { | ||
| 319 | 348 | title={t("classGroups.removeStudent")} |
| 320 | 349 | variant="destructive" |
| 321 | 350 | summary={t("classGroups.removeStudentConfirm", { name: removeMember() ? personLabel(removeMember()!.user) : "" })} |
| 322 | - onConfirm={async () => { const target = removeMember(); if (!target) return; await wrap(async () => { await deleteClassMember(id(), target.user.id); await refetchMembers(); setRemoveMember(null); }, "common.deleted"); }} | |
| 351 | + onConfirm={async () => { const target = removeMember(); if (!target) return; await wrap(async () => { await deleteClassMember(id(), target.user.id); await refresh(refetchMembers); setRemoveMember(null); }, "common.deleted"); }} | |
| 323 | 352 | /> |
| 324 | 353 | |
| 325 | 354 | {/* Detach course */} |
| @@ -329,14 +358,10 @@ function ClassDetailContent() { | ||
| 329 | 358 | title={t("classGroups.detachCourse")} |
| 330 | 359 | variant="destructive" |
| 331 | 360 | summary={t("classGroups.detachCourseConfirm", { course: detachCourse() ? courseTitle(detachCourse()!.course) : "" })} |
| 332 | - onConfirm={async () => { const target = detachCourse(); if (!target) return; await wrap(async () => { await deleteClassCourse(id(), target.course); await refetchCourses(); setDetachCourse(null); }, "common.deleted"); }} | |
| 361 | + onConfirm={async () => { const target = detachCourse(); if (!target) return; await wrap(async () => { await deleteClassCourse(id(), target.course); await refresh(refetchCourses); setDetachCourse(null); }, "common.deleted"); }} | |
| 333 | 362 | /> |
| 334 | 363 | </div> |
| 335 | - )} | |
| 336 | - </Show> | |
| 337 | - }> | |
| 338 | - <Alert variant="destructive">{formatApiError(cls.error)}</Alert> | |
| 339 | - </Show> | |
| 340 | - </Suspense> | |
| 364 | + )} | |
| 365 | + </Show> | |
| 341 | 366 | ); |
| 342 | 367 | } |
src/pages/classes-page.tsxmodified+8 -1
| @@ -103,7 +103,14 @@ function ClassesContent() { | ||
| 103 | 103 | teacher_id: teacherId() || undefined, |
| 104 | 104 | }); |
| 105 | 105 | setName(""); setGrade(""); setTermId(""); setTeacherId(""); setShowForm(false); |
| 106 | - await refetch(); | |
| 106 | + // Reloading the list is housekeeping for a page we are leaving anyway: a | |
| 107 | + // failure here used to be reported as if the class had not been created, | |
| 108 | + // and it swallowed the navigation to the class that plainly existed. | |
| 109 | + try { | |
| 110 | + await refetch(); | |
| 111 | + } catch { | |
| 112 | + // The list reloads on the next visit; the class was created. | |
| 113 | + } | |
| 107 | 114 | setFlash(t("common.created")); |
| 108 | 115 | void navigate({ to: "/management/classes/$id", params: { id: created.id } }); |
| 109 | 116 | } catch (err) { |
src/stores/preferences-context.tsxmodified+13 -0
| @@ -187,6 +187,19 @@ export function PreferencesProvider(props: ParentProps) { | ||
| 187 | 187 | writeStorage(THEME_KEY, th); |
| 188 | 188 | document.documentElement.setAttribute("data-kb-theme", th); |
| 189 | 189 | document.documentElement.classList.toggle("dark", th === "dark"); |
| 190 | + // The boot script paints an inline background on <html> because it runs | |
| 191 | + // before the stylesheet; from here on the stylesheet owns that color, and | |
| 192 | + // a stale literal would survive a theme switch. | |
| 193 | + document.documentElement.style.removeProperty("background-color"); | |
| 194 | + // The system bars (status bar, gesture bar) are painted by the shell from | |
| 195 | + // this meta tag, not from the page, so without the update they keep the | |
| 196 | + // boot value and a switched theme left a white strip framing a dark app. | |
| 197 | + // The value is read back from --background so the two cannot drift apart. | |
| 198 | + const meta = document.querySelector<HTMLMetaElement>('meta[name="theme-color"]'); | |
| 199 | + if (meta) { | |
| 200 | + const background = getComputedStyle(document.documentElement).getPropertyValue("--background").trim(); | |
| 201 | + if (background) meta.content = `hsl(${background})`; | |
| 202 | + } | |
| 190 | 203 | }); |
| 191 | 204 | |
| 192 | 205 | createEffect(() => { |