From 4523a07fc0afdc1422bc795f1cd4c51d4cc561b2 Mon Sep 17 00:00:00 2001 From: Andrew S Erwin Date: Tue, 1 Dec 2026 06:50:19 -0600 Subject: [PATCH] Library: /pages (no id) shows the All-pages info view, not auto-opened page - Remove the auto-select-first-page effect so the Library index (filters, folder path, relative edited label, click-to-edit) is actually reachable - Edited column uses Today/Yesterday/Mon D labels computed in the fetch callback - Update mobile regression + e2e to the new /pages landing (index, not editor) --- scripts/e2e.mjs | 5 +++-- scripts/regressions.mjs | 2 +- web/app/(app)/pages/client.tsx | 9 ++------- web/components/library-index.tsx | 23 ++++++++++++++++++----- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/e2e.mjs b/scripts/e2e.mjs index 652c74e..6244ce4 100644 --- a/scripts/e2e.mjs +++ b/scripts/e2e.mjs @@ -58,7 +58,8 @@ try { await page.getByPlaceholder('Password', { exact: true }).fill(password) await page.getByRole('button', { name: 'Sign in with Email', exact: true }).click() await page.waitForURL('**/pages') - await page.getByRole('heading', { name: 'No pages yet', exact: true }).waitFor() + // /pages with no id is the Library "All pages" info view (empty for a new account). + await page.getByRole('heading', { name: 'Library', exact: true }).waitFor() const me = await json(await context.request.get(`${base}/api/me`)) accounts.push(me.user.id) // Target/cleanup identity preflight (review TEST-03): the account created @@ -140,7 +141,7 @@ try { const moved = await json(await context.request.delete(`${base}/api/kanban/columns/${custom.id}`)) assert.equal(moved.moved, 1) await page.goto(`${base}/pages`) - await page.getByRole('button', { name: 'New page', exact: true }).click() + await page.getByRole('button', { name: 'New page', exact: true }).first().click() await page.getByRole('textbox', { name: 'Page title' }).waitFor() // TipTap contenteditable: drive it with keyboard.insertText (fill() does // not work on contenteditable) and watch the workspace save badge. diff --git a/scripts/regressions.mjs b/scripts/regressions.mjs index b0957d5..8486313 100644 --- a/scripts/regressions.mjs +++ b/scripts/regressions.mjs @@ -1015,7 +1015,7 @@ try { } // Drawer: off-canvas by default, hamburger opens it, navigating closes it. - await mobile.goto(`${base}/pages`) + await mobile.goto(`${base}/pages?id=a`) await mobile.locator('[data-page-editor]').waitFor() assert.ok(await drawerClosed(), 'sidebar must start off-canvas on phones') await noOverflow('pages') diff --git a/web/app/(app)/pages/client.tsx b/web/app/(app)/pages/client.tsx index e05feb4..402cc6e 100644 --- a/web/app/(app)/pages/client.tsx +++ b/web/app/(app)/pages/client.tsx @@ -155,13 +155,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) { editorRef.current?.resetContent(draft ?? data.content) }, [autosave]) - useEffect(() => { - const timer = setTimeout(() => loadPages().then((data) => { - if (!activePage.current && data.length) { activePage.current = data[0].id; setActiveId(data[0].id) } - }).catch((e) => console.error('Failed to load pages', e)), 0) - return () => clearTimeout(timer) - }, [loadPages]) - + // /pages with no ?id is the Library "All pages" info view (library-index); + // it must NOT auto-open the first page, or the index would never be seen. useEffect(() => { const timer = setTimeout(() => { if (activeId) loadPage(activeId).catch((e) => console.error('Failed to load page', e)) diff --git a/web/components/library-index.tsx b/web/components/library-index.tsx index a76040e..8d48076 100644 --- a/web/components/library-index.tsx +++ b/web/components/library-index.tsx @@ -15,7 +15,6 @@ import { } from '@/components/ui/dropdown-menu' import { toast } from 'sonner' import { PAGES_CHANGED, type PageSummary } from '@/lib/pages' -import { SafeDate } from '@/components/safe-format' import { useMounted } from '@/components/client-only' import { cn } from '@/lib/utils' @@ -33,16 +32,30 @@ export function LibraryIndex() { const mounted = useMounted() const [pages, setPages] = useState([]) const [recentIds, setRecentIds] = useState>(new Set()) + const [editedLabels, setEditedLabels] = useState>({}) const [filter, setFilter] = useState('all') const load = useCallback(() => { fetch('/api/pages').then((r) => (r.ok ? r.json() : [])).then((d) => { const list: PageSummary[] = Array.isArray(d) ? d : [] setPages(list) - // Recency is computed here (in the fetch callback), not during render, - // so the render path stays pure and hydration-safe. + // Recency + relative edit labels are computed here (in the fetch + // callback), not during render, so the render path stays pure and + // hydration-safe. const now = Date.now() - setRecentIds(new Set(list.filter((p) => p.updatedAt && now - new Date(p.updatedAt).getTime() < 2 * 24 * 60 * 60 * 1000).map((p) => p.id))) + const startOfToday = new Date(); startOfToday.setHours(0, 0, 0, 0) + const recent = new Set() + const labels: Record = {} + for (const p of list) { + if (!p.updatedAt) continue + const t = new Date(p.updatedAt) + if (now - t.getTime() < 2 * 24 * 60 * 60 * 1000) recent.add(p.id) + const day = new Date(t); day.setHours(0, 0, 0, 0) + const days = Math.round((startOfToday.getTime() - day.getTime()) / (24 * 60 * 60 * 1000)) + labels[p.id] = days === 0 ? 'Today' : days === 1 ? 'Yesterday' : t.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) + } + setRecentIds(recent) + setEditedLabels(labels) }).catch(() => {}) }, []) @@ -137,7 +150,7 @@ export function LibraryIndex() { ))} {folderPath(p) || '—'} - {p.updatedAt ? : '—'} + {editedLabels[p.id] ?? '—'}