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:
Andrew S Erwin
2026-11-06 09:21:57 -06:00
parent 0824700e4e
commit dfb5004326
2 changed files with 12 additions and 116 deletions
+2 -106
View File
@@ -7,9 +7,9 @@ import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import { toast } from 'sonner'
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,
Pin, PinOff, Plus, Quote, RotateCcw, Search, Trash2, Type, X,
Pin, PinOff, Plus, Quote, RotateCcw, Trash2, Type, X,
} from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
@@ -23,7 +23,6 @@ import {
PAGES_CHANGED, collectionEmbedMarkdown, descendantPageIds, internalPageId, nextUntitledTitle,
notifyActivePage, notifyPagesChanged, pageLinkMarkdown, parsePageEmbed, type PageSummary,
} from '@/lib/pages'
import { reorderPages } from '@/lib/page-order'
import { fetchLinkPreview } from '@/lib/link-preview'
import { LinkPreviewCard } from '@/components/link-preview-card'
import type { Element, ElementContent } from 'hast'
@@ -184,7 +183,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
const [pages, setPages] = useState<PageSummary[]>([])
const [activeId, setActiveId] = useState<string | null>(initialId)
const [page, setPage] = useState<PageDetail | null>(null)
const [filter, setFilter] = useState('')
const [mode, setMode] = useState<'edit' | 'preview'>('preview')
const [title, setTitle] = useState('')
const [content, setContent] = useState('')
@@ -202,11 +200,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
const [historyBusy, setHistoryBusy] = useState<string | null>(null)
const [slash, setSlash] = useState<{ query: string; start: number } | null>(null)
const [slashIndex, setSlashIndex] = useState(0)
const [tabDrop, setTabDrop] = useState<{ id: string; after: boolean } | null>(null)
const textareaRef = useRef<HTMLTextAreaElement>(null)
const pendingCaret = useRef<number | null>(null)
const suppressTabClick = useRef(false)
const draggedTabRef = useRef<string | null>(null)
const activePage = useRef(initialId)
const loadSequence = 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 () => {
if (!activeId) return
// 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)
}
const visible = pages.filter((p) => p.title.toLowerCase().includes(filter.toLowerCase()))
const looksLikeUrl = /^(https?:\/\/)?[\w-]+(\.[\w-]+)+/i.test(linkQuery.trim())
// 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).
@@ -670,74 +636,6 @@ export function PagesClient({ initialId }: { initialId: string | null }) {
return (
<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 ? (
<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" />
@@ -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>}
<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="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="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>