diff --git a/web/app/(app)/pages/client.tsx b/web/app/(app)/pages/client.tsx index 6fc9e22..6f67411 100644 --- a/web/app/(app)/pages/client.tsx +++ b/web/app/(app)/pages/client.tsx @@ -67,6 +67,8 @@ export function PagesClient({ initialId }: { initialId: string | null }) { 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 [newTagName, setNewTagName] = useState('') + const [newTagColor, setNewTagColor] = useState('#8b5cf6') const [historyOpen, setHistoryOpen] = useState(false) const [revisions, setRevisions] = useState([]) const [revision, setRevision] = useState(null) @@ -406,6 +408,22 @@ export function PagesClient({ initialId }: { initialId: string | null }) { notifyPagesChanged() } + // Create a tag inline from the page and attach it in one step. + const createAndAttachTag = async () => { + const name = newTagName.trim() + if (!name || !activeId) return + const res = await fetch('/api/tags', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, color: newTagColor }) }) + if (!res.ok) { + const e = await res.json().catch(() => null) + toast.error(e?.error ?? 'Could not create tag') + return + } + const tag = await res.json() + setAllTags((cur) => (cur.some((t) => t.id === tag.id) ? cur : [...cur, tag])) + setNewTagName('') + await toggleTag(tag.id, true) + } + useEffect(() => { if (!linkOpen) return const q = linkQuery.trim() @@ -536,6 +554,28 @@ export function PagesClient({ initialId }: { initialId: string | null }) { ))} {(page?.tags ?? []).length === 0 && No tags} +
+ setNewTagName(e.target.value)} + onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); void createAndAttachTag() } }} + placeholder="New tag name" + className="h-8 flex-1 text-sm" + aria-label="New tag name" + /> + +
+
+ {['#8b5cf6', '#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#ec4899', '#6b7280'].map((c) => ( +
{allTags.map((t) => { const on = (page?.tags ?? []).some((x) => x.tag.id === t.id)