Drop the page-tab strip and its < > move controls
Tabs do not scale: every page became a chip in a horizontal scroller with its own drag-reorder and filter. Navigation and reordering now live solely in the sidebar (same lib/page-order permutation helper, PUT /api/pages); the regression covers the sidebar drag in both directions. Empty state and sidebar keep page creation.
This commit is contained in:
+10
-10
@@ -439,24 +439,24 @@ try {
|
|||||||
await inboxColumn.locator('[data-bookmark-id="bookmark-3"]').waitFor()
|
await inboxColumn.locator('[data-bookmark-id="bookmark-3"]').waitFor()
|
||||||
console.log('PASS: kanban drag reorders within a column and moves cards between columns')
|
console.log('PASS: kanban drag reorders within a column and moves cards between columns')
|
||||||
|
|
||||||
// Page tabs share the persisted position with the sidebar; dragging a tab
|
// The sidebar persists the complete order permutation (PUT /api/pages);
|
||||||
// issues the complete order permutation and both surfaces reload. Reset the
|
// drag b above a. Reset the pin from the earlier metadata test so both
|
||||||
// pin from the earlier metadata test so both pages are in one reorder group.
|
// pages are in one reorder group.
|
||||||
pages.get('a').pinned = false
|
pages.get('a').pinned = false
|
||||||
await page.goto(`${base}/pages`)
|
await page.goto(`${base}/pages`)
|
||||||
await page.locator('[data-page-tab="a"]').waitFor()
|
await page.locator('[data-page-id="a"]').waitFor()
|
||||||
await page.locator('[data-page-tab="b"] [data-page-tab-drag]').dragTo(
|
await page.locator('[data-page-id="b"] [data-page-drag-handle]').dragTo(
|
||||||
page.locator('[data-page-tab="a"]'),
|
page.locator('[data-page-id="a"]'),
|
||||||
{ targetPosition: { x: 5, y: 5 } },
|
{ targetPosition: { x: 10, y: 5 } },
|
||||||
)
|
)
|
||||||
await eventually(() => pages.get('b')?.position === 0 && pages.get('a')?.position === 1, 'Page tab drag did not reorder')
|
await eventually(() => pages.get('b')?.position === 0 && pages.get('a')?.position === 1, 'Sidebar page drag did not reorder')
|
||||||
// The sidebar uses the same complete order permutation; drag a back above b.
|
// And drag a back above b.
|
||||||
await page.locator('[data-page-id="a"] [data-page-drag-handle]').dragTo(
|
await page.locator('[data-page-id="a"] [data-page-drag-handle]').dragTo(
|
||||||
page.locator('[data-page-id="b"]'),
|
page.locator('[data-page-id="b"]'),
|
||||||
{ targetPosition: { x: 10, y: 5 } },
|
{ targetPosition: { x: 10, y: 5 } },
|
||||||
)
|
)
|
||||||
await eventually(() => pages.get('a')?.position === 0 && pages.get('b')?.position === 1, 'Sidebar page drag did not reorder')
|
await eventually(() => pages.get('a')?.position === 0 && pages.get('b')?.position === 1, 'Sidebar page drag did not reorder')
|
||||||
console.log('PASS: page tabs and sidebar persist drag reordering')
|
console.log('PASS: sidebar persists drag reordering')
|
||||||
|
|
||||||
// Revocation failure path (review CR-02): when Go's revocation fails, the
|
// Revocation failure path (review CR-02): when Go's revocation fails, the
|
||||||
// local sign-out still completes, but the UI must say so — local cookie
|
// local sign-out still completes, but the UI must say so — local cookie
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import ReactMarkdown from 'react-markdown'
|
|||||||
import remarkGfm from 'remark-gfm'
|
import remarkGfm from 'remark-gfm'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import {
|
import {
|
||||||
ChevronLeft, ChevronRight, Code, CornerUpLeft, Download, Eye, FileText, GripVertical,
|
Code, CornerUpLeft, Download, Eye, FileText,
|
||||||
Heading1, Heading2, Heading3, History, Layers, Link2, List, ListOrdered, ListTodo, Minus, Pencil,
|
Heading1, Heading2, Heading3, History, Layers, Link2, List, ListOrdered, ListTodo, Minus, Pencil,
|
||||||
Pin, PinOff, Plus, Quote, RotateCcw, Search, Trash2, Type, X,
|
Pin, PinOff, Plus, Quote, RotateCcw, Trash2, Type, X,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
PAGES_CHANGED, collectionEmbedMarkdown, descendantPageIds, internalPageId, nextUntitledTitle,
|
PAGES_CHANGED, collectionEmbedMarkdown, descendantPageIds, internalPageId, nextUntitledTitle,
|
||||||
notifyActivePage, notifyPagesChanged, pageLinkMarkdown, parsePageEmbed, type PageSummary,
|
notifyActivePage, notifyPagesChanged, pageLinkMarkdown, parsePageEmbed, type PageSummary,
|
||||||
} from '@/lib/pages'
|
} from '@/lib/pages'
|
||||||
import { reorderPages } from '@/lib/page-order'
|
|
||||||
import { fetchLinkPreview } from '@/lib/link-preview'
|
import { fetchLinkPreview } from '@/lib/link-preview'
|
||||||
import { LinkPreviewCard } from '@/components/link-preview-card'
|
import { LinkPreviewCard } from '@/components/link-preview-card'
|
||||||
import type { Element, ElementContent } from 'hast'
|
import type { Element, ElementContent } from 'hast'
|
||||||
@@ -184,7 +183,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
const [pages, setPages] = useState<PageSummary[]>([])
|
const [pages, setPages] = useState<PageSummary[]>([])
|
||||||
const [activeId, setActiveId] = useState<string | null>(initialId)
|
const [activeId, setActiveId] = useState<string | null>(initialId)
|
||||||
const [page, setPage] = useState<PageDetail | null>(null)
|
const [page, setPage] = useState<PageDetail | null>(null)
|
||||||
const [filter, setFilter] = useState('')
|
|
||||||
const [mode, setMode] = useState<'edit' | 'preview'>('preview')
|
const [mode, setMode] = useState<'edit' | 'preview'>('preview')
|
||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
const [content, setContent] = useState('')
|
const [content, setContent] = useState('')
|
||||||
@@ -202,11 +200,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
const [historyBusy, setHistoryBusy] = useState<string | null>(null)
|
const [historyBusy, setHistoryBusy] = useState<string | null>(null)
|
||||||
const [slash, setSlash] = useState<{ query: string; start: number } | null>(null)
|
const [slash, setSlash] = useState<{ query: string; start: number } | null>(null)
|
||||||
const [slashIndex, setSlashIndex] = useState(0)
|
const [slashIndex, setSlashIndex] = useState(0)
|
||||||
const [tabDrop, setTabDrop] = useState<{ id: string; after: boolean } | null>(null)
|
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||||
const pendingCaret = useRef<number | null>(null)
|
const pendingCaret = useRef<number | null>(null)
|
||||||
const suppressTabClick = useRef(false)
|
|
||||||
const draggedTabRef = useRef<string | null>(null)
|
|
||||||
const activePage = useRef(initialId)
|
const activePage = useRef(initialId)
|
||||||
const loadSequence = useRef(0)
|
const loadSequence = useRef(0)
|
||||||
const selectionSequence = useRef(0)
|
const selectionSequence = useRef(0)
|
||||||
@@ -504,34 +499,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const move = async (dir: -1 | 1) => {
|
|
||||||
if (!activeId) return
|
|
||||||
const idx = pages.findIndex((p) => p.id === activeId)
|
|
||||||
const target = pages[idx + dir]
|
|
||||||
if (idx < 0 || !target) return
|
|
||||||
const next = reorderPages(pages, activeId, target.id, dir > 0)
|
|
||||||
if (next === 'blocked') { toast.error('Pinned and unpinned pages keep separate groups'); return }
|
|
||||||
if (next) await savePageOrder(next)
|
|
||||||
}
|
|
||||||
|
|
||||||
const savePageOrder = async (next: PageSummary[]) => {
|
|
||||||
setPages(next)
|
|
||||||
const res = await fetch('/api/pages', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ order: next.map((p) => p.id) }) })
|
|
||||||
if (!res.ok) { toast.error('Could not reorder pages'); await loadPages(); return }
|
|
||||||
await loadPages()
|
|
||||||
notify()
|
|
||||||
}
|
|
||||||
|
|
||||||
const dropTab = (target: PageSummary, after: boolean) => {
|
|
||||||
const source = draggedTabRef.current
|
|
||||||
draggedTabRef.current = null
|
|
||||||
setTabDrop(null)
|
|
||||||
if (!source) return
|
|
||||||
const next = reorderPages(pages, source, target.id, after)
|
|
||||||
if (next === 'blocked') { toast.error('Pinned and unpinned pages keep separate groups'); return }
|
|
||||||
if (next) void savePageOrder(next)
|
|
||||||
}
|
|
||||||
|
|
||||||
const download = async () => {
|
const download = async () => {
|
||||||
if (!activeId) return
|
if (!activeId) return
|
||||||
// A paused conflict can never flush; exporting the server copy is still
|
// A paused conflict can never flush; exporting the server copy is still
|
||||||
@@ -658,7 +625,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
if (/^https?:\/\/\S+$/i.test(text)) offerTitleForPastedUrl(text)
|
if (/^https?:\/\/\S+$/i.test(text)) offerTitleForPastedUrl(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
const visible = pages.filter((p) => p.title.toLowerCase().includes(filter.toLowerCase()))
|
|
||||||
const looksLikeUrl = /^(https?:\/\/)?[\w-]+(\.[\w-]+)+/i.test(linkQuery.trim())
|
const looksLikeUrl = /^(https?:\/\/)?[\w-]+(\.[\w-]+)+/i.test(linkQuery.trim())
|
||||||
// A page may move under any page except itself or one of its descendants
|
// A page may move under any page except itself or one of its descendants
|
||||||
// (the server rejects that cycle even if a stale client tries it).
|
// (the server rejects that cycle even if a stale client tries it).
|
||||||
@@ -670,74 +636,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
<div className="flex items-center gap-2 border-b border-border/60 px-4 py-2">
|
|
||||||
<div className="relative w-40 shrink-0">
|
|
||||||
<Search className="absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" />
|
|
||||||
<Input value={filter} onChange={(e) => setFilter(e.target.value)} placeholder="Filter pages" className="h-8 pl-7 text-sm" />
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-1 items-center gap-1 overflow-x-auto">
|
|
||||||
{visible.map((p) => (
|
|
||||||
<div
|
|
||||||
key={p.id}
|
|
||||||
data-page-tab={p.id}
|
|
||||||
onDragOver={(e) => {
|
|
||||||
if (!draggedTabRef.current || draggedTabRef.current === p.id) return
|
|
||||||
e.preventDefault()
|
|
||||||
e.dataTransfer.dropEffect = 'move'
|
|
||||||
const rect = e.currentTarget.getBoundingClientRect()
|
|
||||||
setTabDrop({ id: p.id, after: e.clientX > rect.left + rect.width / 2 })
|
|
||||||
}}
|
|
||||||
onDragLeave={(e) => {
|
|
||||||
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setTabDrop(null)
|
|
||||||
}}
|
|
||||||
onDrop={(e) => {
|
|
||||||
e.preventDefault()
|
|
||||||
const rect = e.currentTarget.getBoundingClientRect()
|
|
||||||
dropTab(p, e.clientX > rect.left + rect.width / 2)
|
|
||||||
}}
|
|
||||||
title={filter.trim() ? 'Clear the filter to reorder pages' : 'Drag the grip to reorder page'}
|
|
||||||
className={cn(
|
|
||||||
'group/tab flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-sm transition-colors',
|
|
||||||
p.id === activeId ? 'bg-primary/10 font-medium text-primary' : 'text-muted-foreground hover:bg-muted hover:text-foreground',
|
|
||||||
tabDrop?.id === p.id && 'ring-1 ring-primary/50',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{!filter.trim() && (
|
|
||||||
<span
|
|
||||||
data-page-tab-drag
|
|
||||||
draggable
|
|
||||||
onDragStart={(e) => {
|
|
||||||
suppressTabClick.current = true
|
|
||||||
draggedTabRef.current = p.id
|
|
||||||
e.dataTransfer.effectAllowed = 'move'
|
|
||||||
e.dataTransfer.setData('text/plain', p.id)
|
|
||||||
}}
|
|
||||||
onDragEnd={() => {
|
|
||||||
draggedTabRef.current = null
|
|
||||||
setTabDrop(null)
|
|
||||||
setTimeout(() => { suppressTabClick.current = false }, 0)
|
|
||||||
}}
|
|
||||||
className="cursor-grab text-muted-foreground/40 opacity-0 transition-opacity hover:text-muted-foreground active:cursor-grabbing group-hover/tab:opacity-100"
|
|
||||||
aria-label={`Drag page ${p.title}`}
|
|
||||||
>
|
|
||||||
<GripVertical className="h-3 w-3" />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => { if (!suppressTabClick.current) select(p.id) }}
|
|
||||||
aria-label={p.title}
|
|
||||||
className="flex min-w-0 items-center gap-1.5"
|
|
||||||
>
|
|
||||||
{p.pinned ? <Pin className="h-3 w-3" /> : <FileText className="h-3 w-3" />}
|
|
||||||
<span className="max-w-[10rem] truncate">{p.title}</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<Button size="sm" onClick={createPage}><Plus className="mr-1 h-4 w-4" />New page</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!page || page.id !== activeId ? (
|
{!page || page.id !== activeId ? (
|
||||||
<div className="flex flex-1 flex-col items-center justify-center gap-3 p-10 text-center">
|
<div className="flex flex-1 flex-col items-center justify-center gap-3 p-10 text-center">
|
||||||
<FileText className="h-10 w-10 text-muted-foreground" />
|
<FileText className="h-10 w-10 text-muted-foreground" />
|
||||||
@@ -753,8 +651,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
|
|||||||
{saveState === 'dirty' && <Button size="sm" variant="outline" onClick={() => autosave.flush(page.id)}>Save now</Button>}
|
{saveState === 'dirty' && <Button size="sm" variant="outline" onClick={() => autosave.flush(page.id)}>Save now</Button>}
|
||||||
<Button variant="ghost" size="icon-sm" title={mode === 'edit' ? 'Preview' : 'Edit'} onClick={() => { setMode(mode === 'edit' ? 'preview' : 'edit'); setSlash(null) }}>{mode === 'edit' ? <Eye className="h-4 w-4" /> : <Pencil className="h-4 w-4" />}</Button>
|
<Button variant="ghost" size="icon-sm" title={mode === 'edit' ? 'Preview' : 'Edit'} onClick={() => { setMode(mode === 'edit' ? 'preview' : 'edit'); setSlash(null) }}>{mode === 'edit' ? <Eye className="h-4 w-4" /> : <Pencil className="h-4 w-4" />}</Button>
|
||||||
<Button variant="ghost" size="icon-sm" title={page.pinned ? 'Unpin' : 'Pin to sidebar'} onClick={togglePin}>{page.pinned ? <PinOff className="h-4 w-4" /> : <Pin className="h-4 w-4" />}</Button>
|
<Button variant="ghost" size="icon-sm" title={page.pinned ? 'Unpin' : 'Pin to sidebar'} onClick={togglePin}>{page.pinned ? <PinOff className="h-4 w-4" /> : <Pin className="h-4 w-4" />}</Button>
|
||||||
<Button variant="ghost" size="icon-sm" title="Move tab left" onClick={() => move(-1)}><ChevronLeft className="h-4 w-4" /></Button>
|
|
||||||
<Button variant="ghost" size="icon-sm" title="Move tab right" onClick={() => move(1)}><ChevronRight className="h-4 w-4" /></Button>
|
|
||||||
<Button variant="ghost" size="icon-sm" title="Download .md" onClick={download}><Download className="h-4 w-4" /></Button>
|
<Button variant="ghost" size="icon-sm" title="Download .md" onClick={download}><Download className="h-4 w-4" /></Button>
|
||||||
<Button variant="ghost" size="icon-sm" title="Version history" onClick={() => void openHistory()}><History className="h-4 w-4" /></Button>
|
<Button variant="ghost" size="icon-sm" title="Version history" onClick={() => void openHistory()}><History className="h-4 w-4" /></Button>
|
||||||
<Button variant="ghost" size="icon-sm" title="Move to trash" onClick={remove}><Trash2 className="h-4 w-4 text-destructive" /></Button>
|
<Button variant="ghost" size="icon-sm" title="Move to trash" onClick={remove}><Trash2 className="h-4 w-4 text-destructive" /></Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user