diff --git a/web/app/(app)/pages/client.tsx b/web/app/(app)/pages/client.tsx index 2e3ede7..6fc9e22 100644 --- a/web/app/(app)/pages/client.tsx +++ b/web/app/(app)/pages/client.tsx @@ -4,7 +4,7 @@ import { useCallback, useEffect, useRef, useState } from 'react' import { useRouter } from 'next/navigation' import { toast } from 'sonner' import { - CornerUpLeft, Download, FileText, History, Layers, Link2, Pin, PinOff, Plus, RotateCcw, Trash2, X, + CornerUpLeft, Download, FileText, History, Layers, Link2, Pin, PinOff, Plus, RotateCcw, Tags, Trash2, X, } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' @@ -65,6 +65,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) { const [pageLinkQuery, setPageLinkQuery] = useState('') const [embedOpen, setEmbedOpen] = useState(false) const [collections, setCollections] = useState<{ id: string; name: string; icon: string | null; views?: { id: string; name: string }[] }[]>([]) + const [tagsOpen, setTagsOpen] = useState(false) + const [allTags, setAllTags] = useState<{ id: string; name: string; color: string }[]>([]) const [historyOpen, setHistoryOpen] = useState(false) const [revisions, setRevisions] = useState([]) const [revision, setRevision] = useState(null) @@ -374,6 +376,36 @@ export function PagesClient({ initialId }: { initialId: string | null }) { .catch(() => { /* transient; reopening retries */ }) }, [embedOpen]) + // Page tags: the picker lists the owner's tags; toggling uses the dedicated + // metadata endpoints (no content version involved). + useEffect(() => { + if (!tagsOpen) return + fetch('/api/tags') + .then((res) => (res.ok ? res.json() : [])) + .then((data) => setAllTags(Array.isArray(data) ? data : [])) + .catch(() => { /* transient; reopening retries */ }) + }, [tagsOpen]) + + const toggleTag = async (tagId: string, attach: boolean) => { + if (!activeId || page?.id !== activeId) return + const res = attach + ? await fetch(`/api/pages/${activeId}/tags`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tagId }) }) + : await fetch(`/api/pages/${activeId}/tags/${tagId}`, { method: 'DELETE' }) + if (!res.ok) { toast.error('Could not update tags'); return } + const tag = allTags.find((t) => t.id === tagId) + setPage((cur) => { + if (!cur || cur.id !== activeId) return cur + const tags = cur.tags ?? [] + return { + ...cur, + tags: attach + ? (tags.some((t) => t.tag.id === tagId) ? tags : [...tags, { tag: tag ?? { id: tagId, name: '', color: '#888888' } }]) + : tags.filter((t) => t.tag.id !== tagId), + } + }) + notifyPagesChanged() + } + useEffect(() => { if (!linkOpen) return const q = linkQuery.trim() @@ -490,6 +522,35 @@ export function PagesClient({ initialId }: { initialId: string | null }) { {parentOptions.map((p) => )} + + + + + +
+ {(page?.tags ?? []).map((t) => ( + + {t.tag.name} + + + ))} + {(page?.tags ?? []).length === 0 && No tags} +
+
+ {allTags.map((t) => { + const on = (page?.tags ?? []).some((x) => x.tag.id === t.id) + return ( + + ) + })} + {allTags.length === 0 &&

No tags yet. Create one from Tags first.

} +
+
+
{ setPageLinkOpen(open); if (!open) setPageLinkQuery('') }}>