forge
Explore
Log in

Don't you dare go Hollow

📌 sticky table headers, list position on Back, scroll-fed appointments

Browse files at this commit

c513a0cfa884079af1e4fdc37304b2caa221db49Burak BoduroğluParent: 33fa92d
  • feat
    • 📌 sticky table headers, list position on Back, scroll-fed appointments
Show full message
feat: 📌 sticky table headers, list position on Back, scroll-fed appointments
- a table that fits keeps its header row pinned under the app top bar
  while the page scrolls (its frame only clips instead of scrolling)
- DataTable remembers how many rows were revealed and the page offset per
  history entry; Back from a detail page redraws them and lands on the
  same row, a fresh visit still starts at the top
- createInfiniteList gains refresh() (re-read loaded rows in place) and
  restoreKey (reload as many rows as before); converted lists use both
- appointments load slots and bookings page by page instead of stopping
  at the first 100; the 30s poll refreshes in place
- selected filled tiles (user menu, theme picker, date picker, unread
  pills) drop the border that matched their fill
src/components/exams/exam-room-ws.tsxmodified+1 -1
@@ -898,7 +898,7 @@ function QuestionAnswerCardWS(props: {
898898 setValue(choice.id);
899899 }}
900900 >
901- <span class={value() === choice.id ? "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-primary bg-primary text-xs font-semibold text-primary-foreground" : "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-input bg-background text-xs font-semibold text-foreground"}>
901+ <span class={value() === choice.id ? "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-transparent bg-primary bg-clip-padding text-xs font-semibold text-primary-foreground" : "flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-input bg-background text-xs font-semibold text-foreground"}>
902902 {String.fromCharCode(65 + choiceIndex())}
903903 </span>
904904 <span class="min-w-0 space-y-2">
src/components/layout/celebi-panel.tsxmodified+1 -1
@@ -557,7 +557,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean
557557 type="button"
558558 class={cn(
559559 "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",
560- unread() ? "border-primary bg-primary text-primary-foreground hover:bg-primary/90" : "border-border bg-card/95 text-foreground hover:bg-accent",
560+ 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",
561561 )}
562562 onClick={scrollToLatest}
563563 >
src/components/layout/theme-mode-control.tsxmodified+2 -2
@@ -54,11 +54,11 @@ export function ThemeModeControl(props: ThemeModeControlProps) {
5454
5555 return (
5656 <div class="grid grid-cols-2 gap-2" role="group" aria-label={prefs.t("theme.toggle")}>
57- <button type="button" role="menuitemradio" aria-checked={!isDark()} class={cn("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", !isDark() ? "border-primary bg-primary text-primary-foreground shadow-xs" : "border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground")} onClick={() => selectTheme("light")}>
57+ <button type="button" role="menuitemradio" aria-checked={!isDark()} class={cn("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", !isDark() ? "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={() => selectTheme("light")}>
5858 <span class="flex h-7 w-7 items-center justify-center"><IconSun class="h-5 w-5" /></span>
5959 <span class="leading-tight">{lightLabel()}</span>
6060 </button>
61- <button type="button" role="menuitemradio" aria-checked={isDark()} class={cn("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", isDark() ? "border-primary bg-primary text-primary-foreground shadow-xs" : "border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground")} onClick={() => selectTheme("dark")}>
61+ <button type="button" role="menuitemradio" aria-checked={isDark()} class={cn("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", isDark() ? "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={() => selectTheme("dark")}>
6262 <span class="flex h-7 w-7 items-center justify-center"><IconMoon class="h-5 w-5" /></span>
6363 <span class="leading-tight">{darkLabel()}</span>
6464 </button>
src/components/layout/user-menu.tsxmodified+1 -1
@@ -50,7 +50,7 @@ function ChoiceButton(props: {
5050 "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",
5151 "outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
5252 props.active
53- ? "border-primary bg-primary text-primary-foreground shadow-xs"
53+ ? "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs"
5454 : "border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground",
5555 )}
5656 onClick={props.onSelect}
src/components/rag/rag-study-panel.tsxmodified+1 -1
@@ -527,7 +527,7 @@ export function RagStudyPanel() {
527527 class={cn(
528528 "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",
529529 unread()
530- ? "border-primary bg-primary text-primary-foreground hover:bg-primary/90"
530+ ? "border-transparent bg-primary bg-clip-padding text-primary-foreground hover:bg-primary/90"
531531 : "border-border bg-surface-base/95 text-foreground hover:bg-surface-overlay",
532532 )}
533533 onClick={scrollToLatest}
src/components/ui/data-table.tsxmodified+74 -2
@@ -1,4 +1,4 @@
1-import { For, Show, createEffect, createSignal, on, onCleanup } from "solid-js";
1+import { For, Show, createEffect, createSignal, on, onCleanup, onMount } from "solid-js";
22 import type { JSX, ParentProps } from "solid-js";
33 import {
44 type Column,
@@ -159,8 +159,39 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData,
159159 // Client-side tables drop page numbers for scroll-to-reveal; only a
160160 // server-paged table (`manualPagination`) still pages.
161161 const revealing = () => paginationEnabled && !props.manualPagination && !props.infinite;
162- const [revealed, setRevealed] = createSignal(REVEAL_STEP);
162+ // How far the reader had revealed, per page and table, for this tab: coming
163+ // back from a detail page renders those rows again, so the router's scroll
164+ // restoration has somewhere to land.
165+ const revealKey = typeof window === "undefined"
166+ ? null
167+ : `reveal:${window.location.pathname}${window.location.search}:${props.storageKey ?? props.title ?? ""}`;
168+ const readRevealed = () => {
169+ try {
170+ const count = Number(revealKey ? sessionStorage.getItem(revealKey) : null);
171+ return Number.isFinite(count) && count > REVEAL_STEP ? Math.floor(count) : REVEAL_STEP;
172+ } catch {
173+ return REVEAL_STEP;
174+ }
175+ };
176+ const [revealed, setRevealed] = createSignal(readRevealed());
177+ createEffect(on(revealed, (count) => {
178+ if (!revealKey || count === Number.MAX_SAFE_INTEGER) return;
179+ try {
180+ sessionStorage.setItem(revealKey, String(count));
181+ } catch {
182+ // storage blocked: the table just starts at the first step
183+ }
184+ }, { defer: true }));
163185 const resetReveal = () => setRevealed(REVEAL_STEP);
186+ // The router's own scroll restoration runs before a list's rows arrive, so
187+ // a long list came back at the top. Remember the page offset against this
188+ // history entry and put it back once the rows are drawn — only on a return
189+ // to the same entry (Back), never on a fresh visit.
190+ const scrollKey = revealKey ? `${revealKey}:scroll` : null;
191+ const historyEntry = () => {
192+ const state = history.state as Record<string, unknown> | null;
193+ return String(state?.__TSR_key ?? state?.key ?? "");
194+ };
164195 createEffect(on(() => props.pageResetKey, resetReveal, { defer: true }));
165196 // The search box's text when the table owns it — the `searchPredicate`
166197 // query, or the `filterColumn` filter value.
@@ -370,6 +401,47 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData,
370401 if (busy === false && observing) queueMicrotask(revealMore);
371402 }, { defer: true }));
372403 if (!observing) setRevealed(Number.MAX_SAFE_INTEGER);
404+ if (scrollKey) {
405+ let saveTimer: ReturnType<typeof setTimeout> | undefined;
406+ const saveScroll = () => {
407+ clearTimeout(saveTimer);
408+ saveTimer = setTimeout(() => {
409+ try {
410+ sessionStorage.setItem(scrollKey, JSON.stringify({ y: Math.round(window.scrollY), entry: historyEntry() }));
411+ } catch {
412+ // storage blocked: no restore, nothing else breaks
413+ }
414+ }, 150);
415+ };
416+ onMount(() => {
417+ window.addEventListener("scroll", saveScroll, { passive: true });
418+ onCleanup(() => {
419+ clearTimeout(saveTimer);
420+ window.removeEventListener("scroll", saveScroll);
421+ });
422+ });
423+ let restored = false;
424+ createEffect(() => {
425+ if (restored || visibleRows().length === 0) return;
426+ restored = true;
427+ try {
428+ const saved = JSON.parse(sessionStorage.getItem(scrollKey) ?? "null") as { y?: number; entry?: string } | null;
429+ // The router may already have tried, clamped to a page that was still
430+ // short; correct it once the rows are laid out, and once more after
431+ // late content (avatars, badges) settles.
432+ const target = saved?.y;
433+ if (target && saved.entry === historyEntry()) {
434+ const settle = () => {
435+ if (Math.abs(window.scrollY - target) > 8) window.scrollTo(0, target);
436+ };
437+ requestAnimationFrame(settle);
438+ setTimeout(settle, 300);
439+ }
440+ } catch {
441+ // malformed entry: start at the top
442+ }
443+ });
444+ }
373445 const searchFieldValue = () => {
374446 if (props.onSearchInput || props.searchPredicate || props.filterColumn) return searchValue();
375447 return "";
src/components/ui/date-picker.tsxmodified+1 -1
@@ -200,7 +200,7 @@ export function DatePicker(props: {
200200 class={cn(
201201 "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",
202202 isSameDay(today, day()) && "border-primary/50 text-primary-text",
203- sameDay(selected(), day()) && "border-primary bg-primary text-primary-foreground shadow-xs hover:bg-primary/90 hover:text-primary-foreground",
203+ sameDay(selected(), day()) && "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs hover:bg-primary/90 hover:text-primary-foreground",
204204 )}
205205 onClick={(event) => {
206206 event.stopPropagation();
src/components/ui/draw-canvas.tsxmodified+1 -1
@@ -360,7 +360,7 @@ export function DrawCanvas(props: {
360360 cn(
361361 "flex h-11 w-11 items-center justify-center rounded-lg border transition-colors",
362362 active
363- ? "border-primary bg-primary text-primary-foreground shadow-xs"
363+ ? "border-transparent bg-primary bg-clip-padding text-primary-foreground shadow-xs"
364364 : "border-border bg-background text-muted-foreground hover:bg-accent hover:text-foreground",
365365 );
366366
src/index.cssmodified+20 -0
@@ -260,6 +260,26 @@
260260 border-right-color: var(--color-border-hairline);
261261 }
262262
263+/* The header row stays in view while the page scrolls. `overflow-x: auto`
264+ * makes the frame its own scroller, which pins a sticky thead inside a box
265+ * that never scrolls vertically; a table that fits needs no sideways scroll,
266+ * so its frame only clips (rounded corners) and the thead sticks to the
267+ * page instead. A table wide enough to scroll sideways keeps its scroller
268+ * and a header that scrolls with it. */
269+.data-table-wrap:not([data-scrollable]) {
270+ overflow: clip;
271+}
272+/* In the page (not a side panel) the header clears the app's sticky top
273+ * bar, which only exists from lg up. */
274+#main-content .data-table-wrap:not([data-scrollable]) .data-table thead {
275+ top: 0;
276+}
277+@media (min-width: 64rem) {
278+ #main-content .data-table-wrap:not([data-scrollable]) .data-table thead {
279+ top: calc(49px + env(safe-area-inset-top));
280+ }
281+}
282+
263283 /* İşlemler sütunu: sabit 110x45. */
264284 .data-table td.table-action-cell,
265285 .data-table th.table-action-cell {
src/lib/infinite-list.test.tsxmodified+37 -0
@@ -92,4 +92,41 @@ describe("createInfiniteList", () => {
9292 dispose();
9393 });
9494 });
95+
96+ it("refresh refetches the loaded rows in one request and keeps them", async () => {
97+ const fetch = server(120);
98+ await createRoot(async (dispose) => {
99+ const list = createInfiniteList(() => "r", fetch, { pageSize: 50 });
100+ await flush();
101+ list.loadMore();
102+ await flush();
103+ expect(list.items()).toHaveLength(100);
104+ await list.refresh();
105+ expect(fetch).toHaveBeenLastCalledWith("r", { limit: 100, offset: 0 });
106+ expect(list.items()).toHaveLength(100);
107+ expect(list.hasMore()).toBe(true);
108+ dispose();
109+ });
110+ });
111+
112+ it("restores the loaded row count for a query from session storage", async () => {
113+ sessionStorage.clear();
114+ const fetch = server(120);
115+ await createRoot(async (dispose) => {
116+ const list = createInfiniteList(() => "r", fetch, { pageSize: 50, restoreKey: "t" });
117+ await flush();
118+ list.loadMore();
119+ await flush();
120+ dispose();
121+ });
122+ fetch.mockClear();
123+ await createRoot(async (dispose) => {
124+ const list = createInfiniteList(() => "r", fetch, { pageSize: 50, restoreKey: "t" });
125+ await flush();
126+ expect(fetch).toHaveBeenCalledTimes(1);
127+ expect(fetch).toHaveBeenLastCalledWith("r", { limit: 100, offset: 0 });
128+ expect(list.items()).toHaveLength(100);
129+ dispose();
130+ });
131+ });
95132 });
src/lib/infinite-list.tsmodified+62 -4
@@ -3,6 +3,8 @@ import type { Page, PageParams } from "@/api/client";
33
44 /** Rows fetched per request while the reader scrolls a server-paged list. */
55 export const INFINITE_PAGE_SIZE = 50;
6+/** The most rows one request may ask for when refetching or restoring. */
7+const MAX_BATCH = 500;
68
79 export type InfiniteList<T> = {
810 /** Every row fetched so far, in server order. */
@@ -17,8 +19,14 @@ export type InfiniteList<T> = {
1719 hasMore: () => boolean;
1820 /** Fetch the next page; a no-op while one is in flight or none is left. */
1921 loadMore: () => void;
20- /** Start the current query over from its first page (after a create/delete). */
22+ /** Start the current query over from its first page. */
2123 reload: () => void;
24+ /**
25+ * Refetch every row loaded so far in one request and swap them in place,
26+ * keeping the reader's place (a poll, or after an edit or delete). Skipped
27+ * while a page is in flight.
28+ */
29+ refresh: () => Promise<void>;
2230 /** Patch the loaded rows in place (an edit that needs no refetch). */
2331 mutate: (update: (items: T[]) => T[]) => void;
2432 };
@@ -36,7 +44,16 @@ export type InfiniteList<T> = {
3644 export function createInfiniteList<T, K>(
3745 source: () => K | null | undefined | false,
3846 fetchPage: (key: K, params: PageParams) => Promise<Page<T>>,
39- options: { pageSize?: number; equals?: (a: K, b: K) => boolean } = {},
47+ options: {
48+ pageSize?: number;
49+ equals?: (a: K, b: K) => boolean;
50+ /**
51+ * Remember how many rows were loaded (per query, for this tab) so coming
52+ * back from a detail page loads them again in one request and the
53+ * browser's scroll restoration has the rows to land on.
54+ */
55+ restoreKey?: string;
56+ } = {},
4057 ): InfiniteList<T> {
4158 const pageSize = options.pageSize ?? INFINITE_PAGE_SIZE;
4259 const [items, setItems] = createSignal<T[]>([]);
@@ -48,23 +65,48 @@ export function createInfiniteList<T, K>(
4865 let generation = 0;
4966 let key: K | null = null;
5067
68+ const storageKey = () => (options.restoreKey && key !== null ? `infinite:${options.restoreKey}:${JSON.stringify(key)}` : null);
69+ const savedCount = () => {
70+ const name = storageKey();
71+ if (!name) return 0;
72+ try {
73+ const count = Number(sessionStorage.getItem(name));
74+ return Number.isFinite(count) ? Math.min(Math.max(0, Math.floor(count)), MAX_BATCH) : 0;
75+ } catch {
76+ return 0;
77+ }
78+ };
79+ const saveCount = (count: number) => {
80+ const name = storageKey();
81+ if (!name) return;
82+ try {
83+ sessionStorage.setItem(name, String(count));
84+ } catch {
85+ // storage full or blocked: the list still works, it just starts short
86+ }
87+ };
88+
5189 const fetchNext = async () => {
5290 if (key === null || loading()) return;
5391 const run = generation;
5492 const current = key;
5593 const offset = items().length;
94+ // The first page of a query restored from session storage asks for as
95+ // many rows as were loaded before, in one request.
96+ const limit = offset === 0 ? Math.max(pageSize, savedCount()) : pageSize;
5697 setLoading(true);
5798 setError(undefined);
5899 try {
59- const page = await fetchPage(current, { limit: pageSize, offset });
100+ const page = await fetchPage(current, { limit, offset });
60101 if (run !== generation) return;
61102 const rows = Array.isArray(page.items) ? page.items : [];
62103 setItems((prev) => (offset === 0 ? rows : [...prev, ...rows]));
63104 const next = offset + rows.length;
64105 // A short page ends the list even if `total` says otherwise, so a stale
65106 // count never keeps asking for pages that are not there.
66- setTotal(rows.length < pageSize ? next : Math.max(typeof page.total === "number" ? page.total : next, next));
107+ setTotal(rows.length < limit ? next : Math.max(typeof page.total === "number" ? page.total : next, next));
67108 setLoaded(true);
109+ saveCount(next);
68110 } catch (err) {
69111 if (run === generation) setError(err);
70112 } finally {
@@ -107,6 +149,22 @@ export function createInfiniteList<T, K>(
107149 if (hasMore()) void fetchNext();
108150 },
109151 reload: start,
152+ refresh: async () => {
153+ if (key === null || loading() || !loaded()) return;
154+ const run = generation;
155+ const current = key;
156+ const limit = Math.min(Math.max(pageSize, items().length), MAX_BATCH);
157+ try {
158+ const page = await fetchPage(current, { limit, offset: 0 });
159+ if (run !== generation) return;
160+ const rows = Array.isArray(page.items) ? page.items : [];
161+ setItems(rows);
162+ setTotal(rows.length < limit ? rows.length : Math.max(typeof page.total === "number" ? page.total : rows.length, rows.length));
163+ setError(undefined);
164+ } catch (err) {
165+ if (run === generation) setError(err);
166+ }
167+ },
110168 mutate: (update) => setItems((prev) => update(prev)),
111169 };
112170 }
src/pages/appointments-page.test.tsxmodified+3 -2
@@ -58,6 +58,7 @@ test("separates bookings and available times into tabs", async () => {
5858 // teacher=me) and their own bookings without a start window: neither read
5959 // downloads history.
6060 await waitFor(() => expect(getSlots).toHaveBeenCalled());
61- expect(getSlots).toHaveBeenCalledWith({ starts_after: expect.any(Number), limit: 100 });
62- expect(getAppointments).toHaveBeenCalledWith({ limit: 100 });
61+ // First scroll page only, not a silent 100-row cap.
62+ expect(getSlots).toHaveBeenCalledWith({ starts_after: expect.any(Number), limit: 50, offset: 0 });
63+ expect(getAppointments).toHaveBeenCalledWith({ limit: 50, offset: 0 });
6364 });
src/pages/appointments-page.tsxmodified+40 -38
@@ -1,5 +1,5 @@
11 import { Show, createMemo, createSignal } from "solid-js";
2-import { createResource } from "@/lib/create-resource";
2+import { createInfiniteList } from "@/lib/infinite-list";
33 import type { ColumnDef } from "@tanstack/solid-table";
44 import {
55 deleteSlotById,
@@ -45,8 +45,6 @@ import { hasMinRole } from "@/lib/roles";
4545 import { useAuth } from "@/stores/auth-context";
4646 import { usePreferences, useT } from "@/stores/preferences-context";
4747
48-const PAGE_SIZE = 10;
49-const PAGE_LIMIT = 100;
5048 const isLive = (status: AppointmentStatus) => status === "pending" || status === "approved";
5149
5250 export default function AppointmentsPage() {
@@ -81,23 +79,31 @@ function AppointmentsContent() {
8179 // existed because the endpoint had neither a window nor a teacher filter.
8280 // Non-manager staff get their own published slots (`teacher=me`); managers
8381 // supervise every teacher's, requesters everyone's open ones.
84- const fetchSlots = async () => {
85- const params: SlotListParams = { starts_after: Date.now(), limit: PAGE_LIMIT };
86- if (isStaff() && !isManager()) params.teacher = "me";
87- return (await getSlots(params)).items;
88- };
89- const [slots, { refetch: refetchSlots }] = createResource(fetchSlots);
90- // Appointments come back newest-first (`ORDER BY id DESC`), so page one is
91- // right. The requests table shows decided rows too, so no status window;
92- // non-manager staff narrow to their own rows server-side (`teacher=me`).
93- const [appts, { refetch: refetchAppts }] = createResource(async () => {
94- const params: AppointmentListParams = { limit: PAGE_LIMIT };
95- if (isStaff() && !isManager()) params.teacher = "me";
96- return (await getAppointments(params)).items;
82+ // Both lists load a page at a time as the reader scrolls (they used to stop
83+ // silently at the first 100). The query is the role scope only; the slot
84+ // window's `starts_after` is taken at each fetch so a poll drops slots that
85+ // have started meanwhile.
86+ const scope = () => (auth.user() ? (isStaff() && !isManager() ? "me" : "all") : null);
87+ const slotList = createInfiniteList(scope, (teacher, paging) => {
88+ const params: SlotListParams = { ...paging, starts_after: Date.now() };
89+ if (teacher === "me") params.teacher = "me";
90+ return getSlots(params);
91+ });
92+ // Appointments come back newest-first (`ORDER BY id DESC`). The requests
93+ // table shows decided rows too, so no status window; non-manager staff
94+ // narrow to their own rows server-side (`teacher=me`).
95+ const apptList = createInfiniteList(scope, (teacher, paging) => {
96+ const params: AppointmentListParams = { ...paging };
97+ if (teacher === "me") params.teacher = "me";
98+ return getAppointments(params);
9799 });
100+ const slots = () => slotList.items();
101+ const appts = () => apptList.items();
98102
99- const refetchAll = () => Promise.all([refetchSlots(), refetchAppts()]);
100- const loaded = () => slots.latest !== undefined && appts.latest !== undefined;
103+ // Polls and actions re-read the loaded rows in place, so a status change
104+ // never throws the reader back to the top of a long list.
105+ const refetchAll = () => Promise.all([slotList.refresh(), apptList.refresh()]);
106+ const loaded = () => !slotList.initialLoading() && !apptList.initialLoading();
101107
102108 // Poll so statuses stay in sync when the other party acts (approve, book,
103109 // cancel…). Visibility-aware: pauses on hidden tabs, refetches on tab-back so
@@ -199,8 +205,8 @@ function AppointmentsContent() {
199205
200206 // --- staff: my published slots (the server already narrows to `teacher=me`
201207 // for non-manager staff; managers see every teacher's) ---
202- const mySlots = () => slots.latest ?? [];
203- const slotBooking = (slotId: string) => (appts.latest ?? []).find((a) => a.slot === slotId && isLive(a.status));
208+ const mySlots = () => slots();
209+ const slotBooking = (slotId: string) => appts().find((a) => a.slot === slotId && isLive(a.status));
204210
205211 const slotColumns = createMemo<ColumnDef<AppointmentSlot>[]>(() => [
206212 ...windowColumns<AppointmentSlot>(),
@@ -247,7 +253,7 @@ function AppointmentsContent() {
247253
248254 // --- staff: booking requests for my slots (server-narrowed via `teacher=me`
249255 // for non-manager staff, as with the slots above) ---
250- const requests = () => appts.latest ?? [];
256+ const requests = () => appts();
251257
252258 const requestColumns = createMemo<ColumnDef<Appointment>[]>(() => [
253259 {
@@ -283,13 +289,13 @@ function AppointmentsContent() {
283289 ]);
284290
285291 // --- booker: available slots ---
286- const myLiveSlotIds = () => new Set((appts.latest ?? []).filter((a) => a.requester.id === me()?.id && isLive(a.status)).map((a) => a.slot));
292+ const myLiveSlotIds = () => new Set(appts().filter((a) => a.requester.id === me()?.id && isLive(a.status)).map((a) => a.slot));
287293 const availableSlots = () => {
288294 const taken = myLiveSlotIds();
289295 // `book` refuses a slot whose window has OPENED ("the slot has already
290296 // started", no skew grace), not one that has ended — an in-progress slot
291297 // listed here would show a Book button that always 409s.
292- return (slots.latest ?? []).filter((s) => s.starts_at > now() && !taken.has(s.id));
298+ return slots().filter((s) => s.starts_at > now() && !taken.has(s.id));
293299 };
294300
295301 const availableColumns = createMemo<ColumnDef<AppointmentSlot>[]>(() => [
@@ -316,7 +322,7 @@ function AppointmentsContent() {
316322 ]);
317323
318324 // --- booker: my bookings ---
319- const myBookings = () => (appts.latest ?? []).filter((a) => a.requester.id === me()?.id);
325+ const myBookings = () => appts().filter((a) => a.requester.id === me()?.id);
320326 const nextBooking = createMemo(() =>
321327 myBookings()
322328 .filter((a) => isLive(a.status) && a.starts_at != null && a.starts_at > now())
@@ -440,14 +446,14 @@ function AppointmentsContent() {
440446 <IconCalendarDays class="h-4 w-4" />
441447 {isStaff() ? t("appointments.requests") : t("appointments.myBookings")}
442448 <Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">
443- {isStaff() ? requests().length : myBookings().length}
449+ {apptList.total()}
444450 </Badge>
445451 </TabsTrigger>
446452 <TabsTrigger value="availability" class="min-w-0">
447453 <IconClock class="h-4 w-4" />
448454 {isStaff() ? t("appointments.mySlots") : t("appointments.availableSlots")}
449455 <Badge variant="secondary" class="h-5 min-w-5 justify-center rounded-full px-1.5 py-0 text-[11px] group-data-selected:bg-background group-data-selected:text-foreground">
450- {isStaff() ? mySlots().length : availableSlots().length}
456+ {isStaff() ? slotList.total() : availableSlots().length}
451457 </Badge>
452458 </TabsTrigger>
453459 </TabsList>
@@ -456,7 +462,7 @@ function AppointmentsContent() {
456462 <Show when={isStaff()} fallback={
457463 <section class="space-y-4 p-0">
458464 <Show when={loaded()} fallback={<DataTableSkeleton columns={4} rows={6} />}>
459- <Show when={appts.error}><Alert variant="destructive">{formatApiError(appts.error)}</Alert></Show>
465+ <Show when={apptList.error()}>{(err) => <Alert variant="destructive">{formatApiError(err())}</Alert>}</Show>
460466 <Show when={nextBooking()}>
461467 {(booking) => (
462468 <div class="mb-4 flex flex-wrap items-center gap-3 rounded-xl border border-border-line bg-surface-tint p-4">
@@ -477,8 +483,7 @@ function AppointmentsContent() {
477483 columns={bookingColumns()}
478484 data={myBookings()}
479485 tableClass="table-fixed min-w-[46rem]"
480- enablePagination
481- pageSize={PAGE_SIZE}
486+ infinite={{ hasMore: apptList.hasMore(), loading: apptList.loading(), total: apptList.total(), onLoadMore: apptList.loadMore }}
482487 storageKey="appointment-bookings"
483488 onRowClick={setDetailAppt}
484489 empty={t("appointments.noBookings")}
@@ -488,15 +493,14 @@ function AppointmentsContent() {
488493 }>
489494 <section class="space-y-4 p-0">
490495 <Show when={loaded()} fallback={<DataTableSkeleton columns={5} rows={6} />}>
491- <Show when={appts.error}><Alert variant="destructive">{formatApiError(appts.error)}</Alert></Show>
496+ <Show when={apptList.error()}>{(err) => <Alert variant="destructive">{formatApiError(err())}</Alert>}</Show>
492497 <DataTable
493498 title={t("appointments.requests")}
494499 description={t("appointments.requestsHint")}
495500 columns={requestColumns()}
496501 data={requests()}
497502 tableClass="table-fixed min-w-[46rem]"
498- enablePagination
499- pageSize={PAGE_SIZE}
503+ infinite={{ hasMore: apptList.hasMore(), loading: apptList.loading(), total: apptList.total(), onLoadMore: apptList.loadMore }}
500504 storageKey="appointment-requests"
501505 onRowClick={setDetailAppt}
502506 empty={t("appointments.noRequests")}
@@ -510,15 +514,14 @@ function AppointmentsContent() {
510514 <Show when={isStaff()} fallback={
511515 <section class="space-y-4 p-0">
512516 <Show when={loaded()} fallback={<DataTableSkeleton columns={4} rows={6} />}>
513- <Show when={slots.error}><Alert variant="destructive">{formatApiError(slots.error)}</Alert></Show>
517+ <Show when={slotList.error()}>{(err) => <Alert variant="destructive">{formatApiError(err())}</Alert>}</Show>
514518 <DataTable
515519 title={t("appointments.availableSlots")}
516520 description={t("appointments.availableSlotsHint")}
517521 columns={availableColumns()}
518522 data={availableSlots()}
519523 tableClass="table-fixed min-w-[46rem]"
520- enablePagination
521- pageSize={PAGE_SIZE}
524+ infinite={{ hasMore: slotList.hasMore(), loading: slotList.loading(), total: slotList.total(), onLoadMore: slotList.loadMore }}
522525 storageKey="appointment-available-slots"
523526 onRowClick={setDetailSlot}
524527 empty={t("appointments.noSlots")}
@@ -528,7 +531,7 @@ function AppointmentsContent() {
528531 }>
529532 <section class="space-y-4 p-0">
530533 <Show when={loaded()} fallback={<DataTableSkeleton columns={5} rows={6} />}>
531- <Show when={slots.error}><Alert variant="destructive">{formatApiError(slots.error)}</Alert></Show>
534+ <Show when={slotList.error()}>{(err) => <Alert variant="destructive">{formatApiError(err())}</Alert>}</Show>
532535 <DataTable
533536 title={t("appointments.mySlots")}
534537 description={t("appointments.mySlotsHint")}
@@ -541,8 +544,7 @@ function AppointmentsContent() {
541544 columns={slotColumns()}
542545 data={mySlots()}
543546 tableClass="table-fixed min-w-[46rem]"
544- enablePagination
545- pageSize={PAGE_SIZE}
547+ infinite={{ hasMore: slotList.hasMore(), loading: slotList.loading(), total: slotList.total(), onLoadMore: slotList.loadMore }}
546548 storageKey="appointment-my-slots"
547549 onRowClick={setDetailSlot}
548550 empty={t("appointments.noSlots")}
src/pages/courses-page.tsxmodified+5 -3
@@ -82,9 +82,11 @@ function CoursesContent() {
8282 ...(filters.q ? { q: filters.q } : {}),
8383 ...(filters.taught != null ? { taught: filters.taught } : {}),
8484 }),
85- { equals: (a, b) => a.role === b.role && a.kind === b.kind && a.q === b.q && a.taught === b.taught },
85+ { equals: (a, b) => a.role === b.role && a.kind === b.kind && a.q === b.q && a.taught === b.taught, restoreKey: "courses" },
8686 );
87- const refetch = () => list.reload();
87+ // Edits and deletes re-read the loaded rows in place; the retry after an
88+ // error starts over.
89+ const refetch = () => list.refresh();
8890 const openCourse = (course: Course) => void navigate({ to: "/courses/$id", params: { id: course.id } });
8991 // Catalog rights, as on the detail page: the creator or a manager+.
9092 const canManageCatalog = (course: Course) => {
@@ -273,7 +275,7 @@ function CoursesContent() {
273275
274276 <TabsContent value={pageKind() ?? "all"} class="mt-4 space-y-4 border-0 bg-transparent p-0 shadow-none">
275277 <Show when={list.error()}>
276- {(err) => <ErrorAlert message={formatApiError(err())} onRetry={refetch} />}
278+ {(err) => <ErrorAlert message={formatApiError(err())} onRetry={list.reload} />}
277279 </Show>
278280 <Show when={!list.initialLoading()} fallback={<DataTableSkeleton columns={5} rows={8} />}>
279281 <DataTable
src/pages/messages-page.tsxmodified+4 -2
@@ -62,9 +62,11 @@ export default function MessagesPage() {
6262 const messageList = createInfiniteList(
6363 () => ({ f: folder(), q: debouncedQuery().trim() }),
6464 (args, paging) => getMessages(args.f, { ...paging, ...(args.q ? { q: args.q } : {}) }),
65- { equals: (a, b) => a.f === b.f && a.q === b.q },
65+ { equals: (a, b) => a.f === b.f && a.q === b.q, restoreKey: "messages" },
6666 );
67- const refetch = async () => messageList.reload();
67+ // Moves, deletes and the refresh button re-read the loaded rows in place,
68+ // so acting on a message far down the list keeps the reader there.
69+ const refetch = () => messageList.refresh();
6870
6971 const [unreadCount, { refetch: refetchUnread }] = createResource(
7072 async () => (await getMessages("inbox", { read: false, limit: 1 })).total
src/pages/question-bank-page.tsxmodified+3 -2
@@ -75,10 +75,11 @@ function QuestionBankContent() {
7575 });
7676 return result;
7777 },
78- { equals: (a, b) => JSON.stringify(a) === JSON.stringify(b) },
78+ { equals: (a, b) => JSON.stringify(a) === JSON.stringify(b), restoreKey: "question-bank" },
7979 );
8080 const total = () => list.total();
81- const refetch = () => list.reload();
81+ // An edit or delete refreshes the loaded rows in place, keeping the reader's spot.
82+ const refetch = () => list.refresh();
8283
8384 // Only courses the teacher can author in supply subjects for a new template.
8485 const [courses] = createResource(async () => (await getCourses({ limit: 100 })).items);
src/pages/questions-page.tsxmodified+2 -1
@@ -52,9 +52,10 @@ function QuestionsContent() {
5252 const questions = createInfiniteList(
5353 () => statusFilter(),
5454 (status, paging) => getQuestions(status, paging),
55+ { restoreKey: "questions" },
5556 );
5657 const list = () => questions.items();
57- const refetch = () => questions.reload();
58+ const refetch = () => questions.refresh();
5859
5960 const [askOpen, setAskOpen] = createSignal(location().searchStr.includes("action=new"));
6061 const [questionToDelete, setQuestionToDelete] = createSignal<any | null>(null);
src/pages/whiteboards-page.tsxmodified+1 -0
@@ -44,6 +44,7 @@ function WhiteboardsContent() {
4444 const boards = createInfiniteList(
4545 () => debouncedQuery().trim(),
4646 (q, paging) => getBoards({ ...paging, ...(q ? { q } : {}) }),
47+ { restoreKey: "whiteboards" },
4748 );
4849 const [createOpen, setCreateOpen] = createSignal(false);
4950 const visibleBoards = () => boards.items();