Library: /pages (no id) shows the All-pages info view, not auto-opened page
release gate / check (push) Canceled after 1m2s
release gate / check (push) Canceled after 1m2s
- 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)
This commit is contained in:
+3
-2
@@ -58,7 +58,8 @@ try {
|
|||||||
await page.getByPlaceholder('Password', { exact: true }).fill(password)
|
await page.getByPlaceholder('Password', { exact: true }).fill(password)
|
||||||
await page.getByRole('button', { name: 'Sign in with Email', exact: true }).click()
|
await page.getByRole('button', { name: 'Sign in with Email', exact: true }).click()
|
||||||
await page.waitForURL('**/pages')
|
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`))
|
const me = await json(await context.request.get(`${base}/api/me`))
|
||||||
accounts.push(me.user.id)
|
accounts.push(me.user.id)
|
||||||
// Target/cleanup identity preflight (review TEST-03): the account created
|
// 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}`))
|
const moved = await json(await context.request.delete(`${base}/api/kanban/columns/${custom.id}`))
|
||||||
assert.equal(moved.moved, 1)
|
assert.equal(moved.moved, 1)
|
||||||
await page.goto(`${base}/pages`)
|
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()
|
await page.getByRole('textbox', { name: 'Page title' }).waitFor()
|
||||||
// TipTap contenteditable: drive it with keyboard.insertText (fill() does
|
// TipTap contenteditable: drive it with keyboard.insertText (fill() does
|
||||||
// not work on contenteditable) and watch the workspace save badge.
|
// not work on contenteditable) and watch the workspace save badge.
|
||||||
|
|||||||
@@ -1015,7 +1015,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drawer: off-canvas by default, hamburger opens it, navigating closes it.
|
// 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()
|
await mobile.locator('[data-page-editor]').waitFor()
|
||||||
assert.ok(await drawerClosed(), 'sidebar must start off-canvas on phones')
|
assert.ok(await drawerClosed(), 'sidebar must start off-canvas on phones')
|
||||||
await noOverflow('pages')
|
await noOverflow('pages')
|
||||||
|
|||||||
@@ -155,13 +155,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
editorRef.current?.resetContent(draft ?? data.content)
|
editorRef.current?.resetContent(draft ?? data.content)
|
||||||
}, [autosave])
|
}, [autosave])
|
||||||
|
|
||||||
useEffect(() => {
|
// /pages with no ?id is the Library "All pages" info view (library-index);
|
||||||
const timer = setTimeout(() => loadPages().then((data) => {
|
// it must NOT auto-open the first page, or the index would never be seen.
|
||||||
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])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
if (activeId) loadPage(activeId).catch((e) => console.error('Failed to load page', e))
|
if (activeId) loadPage(activeId).catch((e) => console.error('Failed to load page', e))
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
} from '@/components/ui/dropdown-menu'
|
} from '@/components/ui/dropdown-menu'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { PAGES_CHANGED, type PageSummary } from '@/lib/pages'
|
import { PAGES_CHANGED, type PageSummary } from '@/lib/pages'
|
||||||
import { SafeDate } from '@/components/safe-format'
|
|
||||||
import { useMounted } from '@/components/client-only'
|
import { useMounted } from '@/components/client-only'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
|
|
||||||
@@ -33,16 +32,30 @@ export function LibraryIndex() {
|
|||||||
const mounted = useMounted()
|
const mounted = useMounted()
|
||||||
const [pages, setPages] = useState<PageSummary[]>([])
|
const [pages, setPages] = useState<PageSummary[]>([])
|
||||||
const [recentIds, setRecentIds] = useState<Set<string>>(new Set())
|
const [recentIds, setRecentIds] = useState<Set<string>>(new Set())
|
||||||
|
const [editedLabels, setEditedLabels] = useState<Record<string, string>>({})
|
||||||
const [filter, setFilter] = useState<Filter>('all')
|
const [filter, setFilter] = useState<Filter>('all')
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
fetch('/api/pages').then((r) => (r.ok ? r.json() : [])).then((d) => {
|
fetch('/api/pages').then((r) => (r.ok ? r.json() : [])).then((d) => {
|
||||||
const list: PageSummary[] = Array.isArray(d) ? d : []
|
const list: PageSummary[] = Array.isArray(d) ? d : []
|
||||||
setPages(list)
|
setPages(list)
|
||||||
// Recency is computed here (in the fetch callback), not during render,
|
// Recency + relative edit labels are computed here (in the fetch
|
||||||
// so the render path stays pure and hydration-safe.
|
// callback), not during render, so the render path stays pure and
|
||||||
|
// hydration-safe.
|
||||||
const now = Date.now()
|
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<string>()
|
||||||
|
const labels: Record<string, string> = {}
|
||||||
|
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(() => {})
|
}).catch(() => {})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -137,7 +150,7 @@ export function LibraryIndex() {
|
|||||||
))}
|
))}
|
||||||
</button>
|
</button>
|
||||||
<span className="truncate text-xs text-muted-foreground">{folderPath(p) || '—'}</span>
|
<span className="truncate text-xs text-muted-foreground">{folderPath(p) || '—'}</span>
|
||||||
<span className="text-xs text-muted-foreground">{p.updatedAt ? <SafeDate date={p.updatedAt} localize /> : '—'}</span>
|
<span className="text-xs text-muted-foreground">{editedLabels[p.id] ?? '—'}</span>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<button aria-label={`Actions for ${p.title}`} className="rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground"><MoreHorizontal className="h-4 w-4" /></button>
|
<button aria-label={`Actions for ${p.title}`} className="rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground"><MoreHorizontal className="h-4 w-4" /></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user