From c513a0cfa884079af1e4fdc37304b2caa221db49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sat, 26 Sep 2026 18:28:03 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=93=8C=20sticky=20table=20headers?= =?UTF-8?q?,=20list=20position=20on=20Back,=20scroll-fed=20appointments=20?= =?UTF-8?q?-=20a=20table=20that=20fits=20keeps=20its=20header=20row=20pinn?= =?UTF-8?q?ed=20under=20the=20app=20top=20bar=20=20=20while=20the=20page?= =?UTF-8?q?=20scrolls=20(its=20frame=20only=20clips=20instead=20of=20scrol?= =?UTF-8?q?ling)=20-=20DataTable=20remembers=20how=20many=20rows=20were=20?= =?UTF-8?q?revealed=20and=20the=20page=20offset=20per=20=20=20history=20en?= =?UTF-8?q?try;=20Back=20from=20a=20detail=20page=20redraws=20them=20and?= =?UTF-8?q?=20lands=20on=20the=20=20=20same=20row,=20a=20fresh=20visit=20s?= =?UTF-8?q?till=20starts=20at=20the=20top=20-=20createInfiniteList=20gains?= =?UTF-8?q?=20refresh()=20(re-read=20loaded=20rows=20in=20place)=20and=20?= =?UTF-8?q?=20=20restoreKey=20(reload=20as=20many=20rows=20as=20before);?= =?UTF-8?q?=20converted=20lists=20use=20both=20-=20appointments=20load=20s?= =?UTF-8?q?lots=20and=20bookings=20page=20by=20page=20instead=20of=20stopp?= =?UTF-8?q?ing=20=20=20at=20the=20first=20100;=20the=2030s=20poll=20refres?= =?UTF-8?q?hes=20in=20place=20-=20selected=20filled=20tiles=20(user=20menu?= =?UTF-8?q?,=20theme=20picker,=20date=20picker,=20unread=20=20=20pills)=20?= =?UTF-8?q?drop=20the=20border=20that=20matched=20their=20fill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/exams/exam-room-ws.tsx | 2 +- src/components/layout/celebi-panel.tsx | 2 +- src/components/layout/theme-mode-control.tsx | 4 +- src/components/layout/user-menu.tsx | 2 +- src/components/rag/rag-study-panel.tsx | 2 +- src/components/ui/data-table.tsx | 76 ++++++++++++++++++- src/components/ui/date-picker.tsx | 2 +- src/components/ui/draw-canvas.tsx | 2 +- src/index.css | 20 +++++ src/lib/infinite-list.test.tsx | 37 ++++++++++ src/lib/infinite-list.ts | 66 ++++++++++++++++- src/pages/appointments-page.test.tsx | 5 +- src/pages/appointments-page.tsx | 78 ++++++++++---------- src/pages/courses-page.tsx | 8 +- src/pages/messages-page.tsx | 6 +- src/pages/question-bank-page.tsx | 5 +- src/pages/questions-page.tsx | 3 +- src/pages/whiteboards-page.tsx | 1 + 18 files changed, 259 insertions(+), 62 deletions(-) diff --git a/src/components/exams/exam-room-ws.tsx b/src/components/exams/exam-room-ws.tsx index e73167b..c1417c6 100644 --- a/src/components/exams/exam-room-ws.tsx +++ b/src/components/exams/exam-room-ws.tsx @@ -898,7 +898,7 @@ function QuestionAnswerCardWS(props: { setValue(choice.id); }} > - + {String.fromCharCode(65 + choiceIndex())} diff --git a/src/components/layout/celebi-panel.tsx b/src/components/layout/celebi-panel.tsx index a87a03b..c131562 100644 --- a/src/components/layout/celebi-panel.tsx +++ b/src/components/layout/celebi-panel.tsx @@ -557,7 +557,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean type="button" class={cn( "absolute bottom-3 left-1/2 inline-flex h-8 -translate-x-1/2 items-center gap-1.5 rounded-full border px-3 text-xs font-medium shadow-md backdrop-blur transition-colors", - unread() ? "border-primary bg-primary text-primary-foreground hover:bg-primary/90" : "border-border bg-card/95 text-foreground hover:bg-accent", + unread() ? "border-transparent bg-primary bg-clip-padding text-primary-foreground hover:bg-primary/90" : "border-border bg-card/95 text-foreground hover:bg-accent", )} onClick={scrollToLatest} > diff --git a/src/components/layout/theme-mode-control.tsx b/src/components/layout/theme-mode-control.tsx index 821f809..f0741e5 100644 --- a/src/components/layout/theme-mode-control.tsx +++ b/src/components/layout/theme-mode-control.tsx @@ -54,11 +54,11 @@ export function ThemeModeControl(props: ThemeModeControlProps) { return (
- - diff --git a/src/components/layout/user-menu.tsx b/src/components/layout/user-menu.tsx index 4cfdae8..ab9ddc0 100644 --- a/src/components/layout/user-menu.tsx +++ b/src/components/layout/user-menu.tsx @@ -50,7 +50,7 @@ function ChoiceButton(props: { "flex min-h-16 w-full flex-col items-center justify-center gap-1.5 rounded-md border px-2 py-2.5 text-center text-xs font-medium transition-colors", "outline-hidden focus-visible:ring-2 focus-visible:ring-ring", props.active - ? "border-primary bg-primary text-primary-foreground shadow-xs" + ? "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs" : "border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground", )} onClick={props.onSelect} diff --git a/src/components/rag/rag-study-panel.tsx b/src/components/rag/rag-study-panel.tsx index 37f67d9..fc0728a 100644 --- a/src/components/rag/rag-study-panel.tsx +++ b/src/components/rag/rag-study-panel.tsx @@ -527,7 +527,7 @@ export function RagStudyPanel() { class={cn( "absolute bottom-3 left-1/2 inline-flex h-8 -translate-x-1/2 items-center gap-1.5 rounded-full border px-3 text-xs font-medium shadow-md backdrop-blur transition-colors", unread() - ? "border-primary bg-primary text-primary-foreground hover:bg-primary/90" + ? "border-transparent bg-primary bg-clip-padding text-primary-foreground hover:bg-primary/90" : "border-border bg-surface-base/95 text-foreground hover:bg-surface-overlay", )} onClick={scrollToLatest} diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index 42f4045..3e27c42 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -1,4 +1,4 @@ -import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js"; +import { For, Show, createEffect, createSignal, on, onCleanup, onMount } from "solid-js"; import type { JSX, ParentProps } from "solid-js"; import { type Column, @@ -159,8 +159,39 @@ export function DataTable(props: DataTableProps paginationEnabled && !props.manualPagination && !props.infinite; - const [revealed, setRevealed] = createSignal(REVEAL_STEP); + // How far the reader had revealed, per page and table, for this tab: coming + // back from a detail page renders those rows again, so the router's scroll + // restoration has somewhere to land. + const revealKey = typeof window === "undefined" + ? null + : `reveal:${window.location.pathname}${window.location.search}:${props.storageKey ?? props.title ?? ""}`; + const readRevealed = () => { + try { + const count = Number(revealKey ? sessionStorage.getItem(revealKey) : null); + return Number.isFinite(count) && count > REVEAL_STEP ? Math.floor(count) : REVEAL_STEP; + } catch { + return REVEAL_STEP; + } + }; + const [revealed, setRevealed] = createSignal(readRevealed()); + createEffect(on(revealed, (count) => { + if (!revealKey || count === Number.MAX_SAFE_INTEGER) return; + try { + sessionStorage.setItem(revealKey, String(count)); + } catch { + // storage blocked: the table just starts at the first step + } + }, { defer: true })); const resetReveal = () => setRevealed(REVEAL_STEP); + // The router's own scroll restoration runs before a list's rows arrive, so + // a long list came back at the top. Remember the page offset against this + // history entry and put it back once the rows are drawn — only on a return + // to the same entry (Back), never on a fresh visit. + const scrollKey = revealKey ? `${revealKey}:scroll` : null; + const historyEntry = () => { + const state = history.state as Record | null; + return String(state?.__TSR_key ?? state?.key ?? ""); + }; createEffect(on(() => props.pageResetKey, resetReveal, { defer: true })); // The search box's text when the table owns it — the `searchPredicate` // query, or the `filterColumn` filter value. @@ -370,6 +401,47 @@ export function DataTable(props: DataTableProps | undefined; + const saveScroll = () => { + clearTimeout(saveTimer); + saveTimer = setTimeout(() => { + try { + sessionStorage.setItem(scrollKey, JSON.stringify({ y: Math.round(window.scrollY), entry: historyEntry() })); + } catch { + // storage blocked: no restore, nothing else breaks + } + }, 150); + }; + onMount(() => { + window.addEventListener("scroll", saveScroll, { passive: true }); + onCleanup(() => { + clearTimeout(saveTimer); + window.removeEventListener("scroll", saveScroll); + }); + }); + let restored = false; + createEffect(() => { + if (restored || visibleRows().length === 0) return; + restored = true; + try { + const saved = JSON.parse(sessionStorage.getItem(scrollKey) ?? "null") as { y?: number; entry?: string } | null; + // The router may already have tried, clamped to a page that was still + // short; correct it once the rows are laid out, and once more after + // late content (avatars, badges) settles. + const target = saved?.y; + if (target && saved.entry === historyEntry()) { + const settle = () => { + if (Math.abs(window.scrollY - target) > 8) window.scrollTo(0, target); + }; + requestAnimationFrame(settle); + setTimeout(settle, 300); + } + } catch { + // malformed entry: start at the top + } + }); + } const searchFieldValue = () => { if (props.onSearchInput || props.searchPredicate || props.filterColumn) return searchValue(); return ""; diff --git a/src/components/ui/date-picker.tsx b/src/components/ui/date-picker.tsx index 27db048..44c51d8 100644 --- a/src/components/ui/date-picker.tsx +++ b/src/components/ui/date-picker.tsx @@ -200,7 +200,7 @@ export function DatePicker(props: { class={cn( "inline-flex h-9 items-center justify-center rounded-md border border-transparent p-0 text-xs font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring", isSameDay(today, day()) && "border-primary/50 text-primary-text", - sameDay(selected(), day()) && "border-primary bg-primary text-primary-foreground shadow-xs hover:bg-primary/90 hover:text-primary-foreground", + sameDay(selected(), day()) && "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs hover:bg-primary/90 hover:text-primary-foreground", )} onClick={(event) => { event.stopPropagation(); diff --git a/src/components/ui/draw-canvas.tsx b/src/components/ui/draw-canvas.tsx index 714a407..6f26352 100644 --- a/src/components/ui/draw-canvas.tsx +++ b/src/components/ui/draw-canvas.tsx @@ -360,7 +360,7 @@ export function DrawCanvas(props: { cn( "flex h-11 w-11 items-center justify-center rounded-lg border transition-colors", active - ? "border-primary bg-primary text-primary-foreground shadow-xs" + ? "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs" : "border-border bg-background text-muted-foreground hover:bg-accent hover:text-foreground", ); diff --git a/src/index.css b/src/index.css index aae5ddd..6a37148 100644 --- a/src/index.css +++ b/src/index.css @@ -260,6 +260,26 @@ border-right-color: var(--color-border-hairline); } +/* The header row stays in view while the page scrolls. `overflow-x: auto` + * makes the frame its own scroller, which pins a sticky thead inside a box + * that never scrolls vertically; a table that fits needs no sideways scroll, + * so its frame only clips (rounded corners) and the thead sticks to the + * page instead. A table wide enough to scroll sideways keeps its scroller + * and a header that scrolls with it. */ +.data-table-wrap:not([data-scrollable]) { + overflow: clip; +} +/* In the page (not a side panel) the header clears the app's sticky top + * bar, which only exists from lg up. */ +#main-content .data-table-wrap:not([data-scrollable]) .data-table thead { + top: 0; +} +@media (min-width: 64rem) { + #main-content .data-table-wrap:not([data-scrollable]) .data-table thead { + top: calc(49px + env(safe-area-inset-top)); + } +} + /* İşlemler sütunu: sabit 110x45. */ .data-table td.table-action-cell, .data-table th.table-action-cell { diff --git a/src/lib/infinite-list.test.tsx b/src/lib/infinite-list.test.tsx index 427466c..14c719a 100644 --- a/src/lib/infinite-list.test.tsx +++ b/src/lib/infinite-list.test.tsx @@ -92,4 +92,41 @@ describe("createInfiniteList", () => { dispose(); }); }); + + it("refresh refetches the loaded rows in one request and keeps them", async () => { + const fetch = server(120); + await createRoot(async (dispose) => { + const list = createInfiniteList(() => "r", fetch, { pageSize: 50 }); + await flush(); + list.loadMore(); + await flush(); + expect(list.items()).toHaveLength(100); + await list.refresh(); + expect(fetch).toHaveBeenLastCalledWith("r", { limit: 100, offset: 0 }); + expect(list.items()).toHaveLength(100); + expect(list.hasMore()).toBe(true); + dispose(); + }); + }); + + it("restores the loaded row count for a query from session storage", async () => { + sessionStorage.clear(); + const fetch = server(120); + await createRoot(async (dispose) => { + const list = createInfiniteList(() => "r", fetch, { pageSize: 50, restoreKey: "t" }); + await flush(); + list.loadMore(); + await flush(); + dispose(); + }); + fetch.mockClear(); + await createRoot(async (dispose) => { + const list = createInfiniteList(() => "r", fetch, { pageSize: 50, restoreKey: "t" }); + await flush(); + expect(fetch).toHaveBeenCalledTimes(1); + expect(fetch).toHaveBeenLastCalledWith("r", { limit: 100, offset: 0 }); + expect(list.items()).toHaveLength(100); + dispose(); + }); + }); }); diff --git a/src/lib/infinite-list.ts b/src/lib/infinite-list.ts index 6bf0043..0281544 100644 --- a/src/lib/infinite-list.ts +++ b/src/lib/infinite-list.ts @@ -3,6 +3,8 @@ import type { Page, PageParams } from "@/api/client"; /** Rows fetched per request while the reader scrolls a server-paged list. */ export const INFINITE_PAGE_SIZE = 50; +/** The most rows one request may ask for when refetching or restoring. */ +const MAX_BATCH = 500; export type InfiniteList = { /** Every row fetched so far, in server order. */ @@ -17,8 +19,14 @@ export type InfiniteList = { hasMore: () => boolean; /** Fetch the next page; a no-op while one is in flight or none is left. */ loadMore: () => void; - /** Start the current query over from its first page (after a create/delete). */ + /** Start the current query over from its first page. */ reload: () => void; + /** + * Refetch every row loaded so far in one request and swap them in place, + * keeping the reader's place (a poll, or after an edit or delete). Skipped + * while a page is in flight. + */ + refresh: () => Promise; /** Patch the loaded rows in place (an edit that needs no refetch). */ mutate: (update: (items: T[]) => T[]) => void; }; @@ -36,7 +44,16 @@ export type InfiniteList = { export function createInfiniteList( source: () => K | null | undefined | false, fetchPage: (key: K, params: PageParams) => Promise>, - options: { pageSize?: number; equals?: (a: K, b: K) => boolean } = {}, + options: { + pageSize?: number; + equals?: (a: K, b: K) => boolean; + /** + * Remember how many rows were loaded (per query, for this tab) so coming + * back from a detail page loads them again in one request and the + * browser's scroll restoration has the rows to land on. + */ + restoreKey?: string; + } = {}, ): InfiniteList { const pageSize = options.pageSize ?? INFINITE_PAGE_SIZE; const [items, setItems] = createSignal([]); @@ -48,23 +65,48 @@ export function createInfiniteList( let generation = 0; let key: K | null = null; + const storageKey = () => (options.restoreKey && key !== null ? `infinite:${options.restoreKey}:${JSON.stringify(key)}` : null); + const savedCount = () => { + const name = storageKey(); + if (!name) return 0; + try { + const count = Number(sessionStorage.getItem(name)); + return Number.isFinite(count) ? Math.min(Math.max(0, Math.floor(count)), MAX_BATCH) : 0; + } catch { + return 0; + } + }; + const saveCount = (count: number) => { + const name = storageKey(); + if (!name) return; + try { + sessionStorage.setItem(name, String(count)); + } catch { + // storage full or blocked: the list still works, it just starts short + } + }; + const fetchNext = async () => { if (key === null || loading()) return; const run = generation; const current = key; const offset = items().length; + // The first page of a query restored from session storage asks for as + // many rows as were loaded before, in one request. + const limit = offset === 0 ? Math.max(pageSize, savedCount()) : pageSize; setLoading(true); setError(undefined); try { - const page = await fetchPage(current, { limit: pageSize, offset }); + const page = await fetchPage(current, { limit, offset }); if (run !== generation) return; const rows = Array.isArray(page.items) ? page.items : []; setItems((prev) => (offset === 0 ? rows : [...prev, ...rows])); const next = offset + rows.length; // A short page ends the list even if `total` says otherwise, so a stale // count never keeps asking for pages that are not there. - setTotal(rows.length < pageSize ? next : Math.max(typeof page.total === "number" ? page.total : next, next)); + setTotal(rows.length < limit ? next : Math.max(typeof page.total === "number" ? page.total : next, next)); setLoaded(true); + saveCount(next); } catch (err) { if (run === generation) setError(err); } finally { @@ -107,6 +149,22 @@ export function createInfiniteList( if (hasMore()) void fetchNext(); }, reload: start, + refresh: async () => { + if (key === null || loading() || !loaded()) return; + const run = generation; + const current = key; + const limit = Math.min(Math.max(pageSize, items().length), MAX_BATCH); + try { + const page = await fetchPage(current, { limit, offset: 0 }); + if (run !== generation) return; + const rows = Array.isArray(page.items) ? page.items : []; + setItems(rows); + setTotal(rows.length < limit ? rows.length : Math.max(typeof page.total === "number" ? page.total : rows.length, rows.length)); + setError(undefined); + } catch (err) { + if (run === generation) setError(err); + } + }, mutate: (update) => setItems((prev) => update(prev)), }; } diff --git a/src/pages/appointments-page.test.tsx b/src/pages/appointments-page.test.tsx index 4617daa..6761126 100644 --- a/src/pages/appointments-page.test.tsx +++ b/src/pages/appointments-page.test.tsx @@ -58,6 +58,7 @@ test("separates bookings and available times into tabs", async () => { // teacher=me) and their own bookings without a start window: neither read // downloads history. await waitFor(() => expect(getSlots).toHaveBeenCalled()); - expect(getSlots).toHaveBeenCalledWith({ starts_after: expect.any(Number), limit: 100 }); - expect(getAppointments).toHaveBeenCalledWith({ limit: 100 }); + // First scroll page only, not a silent 100-row cap. + expect(getSlots).toHaveBeenCalledWith({ starts_after: expect.any(Number), limit: 50, offset: 0 }); + expect(getAppointments).toHaveBeenCalledWith({ limit: 50, offset: 0 }); }); diff --git a/src/pages/appointments-page.tsx b/src/pages/appointments-page.tsx index ee0927e..55ebfec 100644 --- a/src/pages/appointments-page.tsx +++ b/src/pages/appointments-page.tsx @@ -1,5 +1,5 @@ import { Show, createMemo, createSignal } from "solid-js"; -import { createResource } from "@/lib/create-resource"; +import { createInfiniteList } from "@/lib/infinite-list"; import type { ColumnDef } from "@tanstack/solid-table"; import { deleteSlotById, @@ -45,8 +45,6 @@ import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 10; -const PAGE_LIMIT = 100; const isLive = (status: AppointmentStatus) => status === "pending" || status === "approved"; export default function AppointmentsPage() { @@ -81,23 +79,31 @@ function AppointmentsContent() { // existed because the endpoint had neither a window nor a teacher filter. // Non-manager staff get their own published slots (`teacher=me`); managers // supervise every teacher's, requesters everyone's open ones. - const fetchSlots = async () => { - const params: SlotListParams = { starts_after: Date.now(), limit: PAGE_LIMIT }; - if (isStaff() && !isManager()) params.teacher = "me"; - return (await getSlots(params)).items; - }; - const [slots, { refetch: refetchSlots }] = createResource(fetchSlots); - // Appointments come back newest-first (`ORDER BY id DESC`), so page one is - // right. The requests table shows decided rows too, so no status window; - // non-manager staff narrow to their own rows server-side (`teacher=me`). - const [appts, { refetch: refetchAppts }] = createResource(async () => { - const params: AppointmentListParams = { limit: PAGE_LIMIT }; - if (isStaff() && !isManager()) params.teacher = "me"; - return (await getAppointments(params)).items; + // Both lists load a page at a time as the reader scrolls (they used to stop + // silently at the first 100). The query is the role scope only; the slot + // window's `starts_after` is taken at each fetch so a poll drops slots that + // have started meanwhile. + const scope = () => (auth.user() ? (isStaff() && !isManager() ? "me" : "all") : null); + const slotList = createInfiniteList(scope, (teacher, paging) => { + const params: SlotListParams = { ...paging, starts_after: Date.now() }; + if (teacher === "me") params.teacher = "me"; + return getSlots(params); + }); + // Appointments come back newest-first (`ORDER BY id DESC`). The requests + // table shows decided rows too, so no status window; non-manager staff + // narrow to their own rows server-side (`teacher=me`). + const apptList = createInfiniteList(scope, (teacher, paging) => { + const params: AppointmentListParams = { ...paging }; + if (teacher === "me") params.teacher = "me"; + return getAppointments(params); }); + const slots = () => slotList.items(); + const appts = () => apptList.items(); - const refetchAll = () => Promise.all([refetchSlots(), refetchAppts()]); - const loaded = () => slots.latest !== undefined && appts.latest !== undefined; + // Polls and actions re-read the loaded rows in place, so a status change + // never throws the reader back to the top of a long list. + const refetchAll = () => Promise.all([slotList.refresh(), apptList.refresh()]); + const loaded = () => !slotList.initialLoading() && !apptList.initialLoading(); // Poll so statuses stay in sync when the other party acts (approve, book, // cancel…). Visibility-aware: pauses on hidden tabs, refetches on tab-back so @@ -199,8 +205,8 @@ function AppointmentsContent() { // --- staff: my published slots (the server already narrows to `teacher=me` // for non-manager staff; managers see every teacher's) --- - const mySlots = () => slots.latest ?? []; - const slotBooking = (slotId: string) => (appts.latest ?? []).find((a) => a.slot === slotId && isLive(a.status)); + const mySlots = () => slots(); + const slotBooking = (slotId: string) => appts().find((a) => a.slot === slotId && isLive(a.status)); const slotColumns = createMemo[]>(() => [ ...windowColumns(), @@ -247,7 +253,7 @@ function AppointmentsContent() { // --- staff: booking requests for my slots (server-narrowed via `teacher=me` // for non-manager staff, as with the slots above) --- - const requests = () => appts.latest ?? []; + const requests = () => appts(); const requestColumns = createMemo[]>(() => [ { @@ -283,13 +289,13 @@ function AppointmentsContent() { ]); // --- booker: available slots --- - const myLiveSlotIds = () => new Set((appts.latest ?? []).filter((a) => a.requester.id === me()?.id && isLive(a.status)).map((a) => a.slot)); + const myLiveSlotIds = () => new Set(appts().filter((a) => a.requester.id === me()?.id && isLive(a.status)).map((a) => a.slot)); const availableSlots = () => { const taken = myLiveSlotIds(); // `book` refuses a slot whose window has OPENED ("the slot has already // started", no skew grace), not one that has ended — an in-progress slot // listed here would show a Book button that always 409s. - return (slots.latest ?? []).filter((s) => s.starts_at > now() && !taken.has(s.id)); + return slots().filter((s) => s.starts_at > now() && !taken.has(s.id)); }; const availableColumns = createMemo[]>(() => [ @@ -316,7 +322,7 @@ function AppointmentsContent() { ]); // --- booker: my bookings --- - const myBookings = () => (appts.latest ?? []).filter((a) => a.requester.id === me()?.id); + const myBookings = () => appts().filter((a) => a.requester.id === me()?.id); const nextBooking = createMemo(() => myBookings() .filter((a) => isLive(a.status) && a.starts_at != null && a.starts_at > now()) @@ -440,14 +446,14 @@ function AppointmentsContent() { {isStaff() ? t("appointments.requests") : t("appointments.myBookings")} - {isStaff() ? requests().length : myBookings().length} + {apptList.total()} {isStaff() ? t("appointments.mySlots") : t("appointments.availableSlots")} - {isStaff() ? mySlots().length : availableSlots().length} + {isStaff() ? slotList.total() : availableSlots().length} @@ -456,7 +462,7 @@ function AppointmentsContent() { }> - {formatApiError(appts.error)} + {(err) => {formatApiError(err())}} {(booking) => (
@@ -477,8 +483,7 @@ function AppointmentsContent() { columns={bookingColumns()} data={myBookings()} tableClass="table-fixed min-w-[46rem]" - enablePagination - pageSize={PAGE_SIZE} + infinite={{ hasMore: apptList.hasMore(), loading: apptList.loading(), total: apptList.total(), onLoadMore: apptList.loadMore }} storageKey="appointment-bookings" onRowClick={setDetailAppt} empty={t("appointments.noBookings")} @@ -488,15 +493,14 @@ function AppointmentsContent() { }>
}> - {formatApiError(appts.error)} + {(err) => {formatApiError(err())}} }> - {formatApiError(slots.error)} + {(err) => {formatApiError(err())}}
}> - {formatApiError(slots.error)} + {(err) => {formatApiError(err())}} a.role === b.role && a.kind === b.kind && a.q === b.q && a.taught === b.taught }, + { equals: (a, b) => a.role === b.role && a.kind === b.kind && a.q === b.q && a.taught === b.taught, restoreKey: "courses" }, ); - const refetch = () => list.reload(); + // Edits and deletes re-read the loaded rows in place; the retry after an + // error starts over. + const refetch = () => list.refresh(); const openCourse = (course: Course) => void navigate({ to: "/courses/$id", params: { id: course.id } }); // Catalog rights, as on the detail page: the creator or a manager+. const canManageCatalog = (course: Course) => { @@ -273,7 +275,7 @@ function CoursesContent() { - {(err) => } + {(err) => } }> ({ f: folder(), q: debouncedQuery().trim() }), (args, paging) => getMessages(args.f, { ...paging, ...(args.q ? { q: args.q } : {}) }), - { equals: (a, b) => a.f === b.f && a.q === b.q }, + { equals: (a, b) => a.f === b.f && a.q === b.q, restoreKey: "messages" }, ); - const refetch = async () => messageList.reload(); + // Moves, deletes and the refresh button re-read the loaded rows in place, + // so acting on a message far down the list keeps the reader there. + const refetch = () => messageList.refresh(); const [unreadCount, { refetch: refetchUnread }] = createResource( async () => (await getMessages("inbox", { read: false, limit: 1 })).total diff --git a/src/pages/question-bank-page.tsx b/src/pages/question-bank-page.tsx index adf701d..9f1cec4 100644 --- a/src/pages/question-bank-page.tsx +++ b/src/pages/question-bank-page.tsx @@ -75,10 +75,11 @@ function QuestionBankContent() { }); return result; }, - { equals: (a, b) => JSON.stringify(a) === JSON.stringify(b) }, + { equals: (a, b) => JSON.stringify(a) === JSON.stringify(b), restoreKey: "question-bank" }, ); const total = () => list.total(); - const refetch = () => list.reload(); + // An edit or delete refreshes the loaded rows in place, keeping the reader's spot. + const refetch = () => list.refresh(); // Only courses the teacher can author in supply subjects for a new template. const [courses] = createResource(async () => (await getCourses({ limit: 100 })).items); diff --git a/src/pages/questions-page.tsx b/src/pages/questions-page.tsx index aa1b93f..82bdb3b 100644 --- a/src/pages/questions-page.tsx +++ b/src/pages/questions-page.tsx @@ -52,9 +52,10 @@ function QuestionsContent() { const questions = createInfiniteList( () => statusFilter(), (status, paging) => getQuestions(status, paging), + { restoreKey: "questions" }, ); const list = () => questions.items(); - const refetch = () => questions.reload(); + const refetch = () => questions.refresh(); const [askOpen, setAskOpen] = createSignal(location().searchStr.includes("action=new")); const [questionToDelete, setQuestionToDelete] = createSignal(null); diff --git a/src/pages/whiteboards-page.tsx b/src/pages/whiteboards-page.tsx index 25b029d..3f713b2 100644 --- a/src/pages/whiteboards-page.tsx +++ b/src/pages/whiteboards-page.tsx @@ -44,6 +44,7 @@ function WhiteboardsContent() { const boards = createInfiniteList( () => debouncedQuery().trim(), (q, paging) => getBoards({ ...paging, ...(q ? { q } : {}) }), + { restoreKey: "whiteboards" }, ); const [createOpen, setCreateOpen] = createSignal(false); const visibleBoards = () => boards.items();