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:
@@ -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<PageSummary[]>([])
|
||||
const [recentIds, setRecentIds] = useState<Set<string>>(new Set())
|
||||
const [editedLabels, setEditedLabels] = useState<Record<string, string>>({})
|
||||
const [filter, setFilter] = useState<Filter>('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<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(() => {})
|
||||
}, [])
|
||||
|
||||
@@ -137,7 +150,7 @@ export function LibraryIndex() {
|
||||
))}
|
||||
</button>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user