* add pb models * api rules has updated to view public * pb setup is completed * add migrate script * add pb migrations * ignore storage * add pocketbase SDK dependency * change Tag.id and PageCardDto.id to string for PocketBase * add DocV1 content block types * add PB client singleton and PB record types * rewrite factory for PocketBase record types * rewrite api.ts for PocketBase SDK * remove unused Strapi files, add PB to config * mark Task 7 complete in plan * feat: verify build, tests, and lint pass with PocketBase API layer * move completed plan: 2026-04-06-pocketbase-api-layer.md * scaffold hudozka-writer with Vite 8, React 19, TS 5.9, Tiptap * add PocketBase client and DocV1 types to writer * add Login component for PocketBase superuser auth * add App shell with auth gate and page loader * add DocV1 <-> Tiptap serialization layer * mark Task 5 complete in writer redesign plan * add custom Tiptap nodes for DocV1 block types * add Tiptap editor with toolbar and save to PocketBase * add image picker with browse and upload * feat: verify writer build and complete integration task * move completed plan: 2026-04-06-hudozka-writer-redesign.md * add local env * rm textblock from writer * add writer editor improvements design spec * add writer editor improvements implementation plan * feat: use @tiptap/markdown for text block serialization * feat: add global markdown/rendered toggle * feat: add BlockMenu component for block type selection * feat: add hover + button for block insertion * feat: add slash commands for block insertion * feat: add interactive file block editor with FilePicker * feat: show resolved page titles in card grid block * move completed plan: 2026-04-07-writer-editor-improvements.md * writer ui improved * pages migration * spec: draft/publish workflow for hudozka-writer * spec: rename draft_doc to draft in spec * plan: writer draft/publish implementation * plan has moved * gitignores * plans upd * feat(writer): update PbPage type for draft/publish workflow * feat(writer): add save/publish/discard handlers with dirty tracking * feat(writer): add DraftBanner component * feat(writer): add Publish button and update toolbar layout * feat(writer): add published toggle and update duplicate for new schema * docs: mark manual verification steps as skipped in writer draft/publish plan * move completed plan: 20260407-writer-draft-publish.md * feat(writer): add BlockActions component for inline block menus * feat(writer): add draggable NodeViews for text blocks * feat(writer): use BlockActions in custom block NodeViews * feat(writer): replace floating BlockInsert with inline BlockActions * fix(writer): ensure all block wrappers have position: relative for BlockActions * chore: mark manual verification tasks as skipped in writer block actions plan * move completed plan: 20260408-writer-block-actions.md * writer update * refactor(writer): simplify BlockActions to always-visible delete + drag handle * feat(writer): add BlockInsert component for inserting blocks between nodes * feat(writer): redesign block sidebar with always-visible actions and insert button * move completed plan: 20260408-writer-block-actions-redesign.md * add spec: textblock container redesign for writer editor * feat(writer): add TextBlock container node definition * feat(writer): replace DraggableXxx wrappers with TextBlock container * feat(writer): update Editor extensions for TextBlock container * feat(writer): add split button to BlockActions for text blocks * feat(writer): update serialization for TextBlock container * feat(writer): update BlockMenu and SlashCommands for TextBlock * fix(writer): use Fragment.from() for replaceWith calls in BlockActions and SlashCommands * move completed plan: 20260408-textblock-container.md * add air
135 lines
3.9 KiB
TypeScript
135 lines
3.9 KiB
TypeScript
import { useState, useEffect, useCallback } from "react"
|
|
import { pb } from "./pb"
|
|
import { Login } from "./components/Login"
|
|
import { Editor } from "./components/Editor"
|
|
import type { PbPage } from "./types"
|
|
import "./App.css"
|
|
|
|
function getSlugFromUrl(): string | null {
|
|
const params = new URLSearchParams(window.location.search)
|
|
return params.get("page")
|
|
}
|
|
|
|
export function App() {
|
|
const [authenticated, setAuthenticated] = useState(pb.authStore.isValid)
|
|
const [page, setPage] = useState<PbPage | null>(null)
|
|
const [loading, setLoading] = useState(false)
|
|
const [error, setError] = useState("")
|
|
|
|
const slug = getSlugFromUrl()
|
|
|
|
const loadPage = useCallback(async (slug: string) => {
|
|
setLoading(true)
|
|
setError("")
|
|
try {
|
|
const record = await pb.collection("pages").getFirstListItem<PbPage>(
|
|
`slug="${slug}"`,
|
|
)
|
|
setPage(record)
|
|
} catch {
|
|
setError(`Page "${slug}" not found`)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (authenticated && slug) {
|
|
loadPage(slug)
|
|
}
|
|
}, [authenticated, slug, loadPage])
|
|
|
|
function handleLogout() {
|
|
pb.authStore.clear()
|
|
setAuthenticated(false)
|
|
setPage(null)
|
|
}
|
|
|
|
async function handleDuplicate() {
|
|
if (!page) return
|
|
const newSlug = `${page.slug}-copy`
|
|
try {
|
|
const record = await pb.collection("pages").create<PbPage>({
|
|
title: `${page.title} (copy)`,
|
|
slug: newSlug,
|
|
excerpt: page.excerpt,
|
|
date: page.date,
|
|
cover: page.cover,
|
|
doc: page.doc,
|
|
tags: page.tags,
|
|
published: false,
|
|
draft: null,
|
|
})
|
|
window.location.search = `?page=${record.slug}`
|
|
} catch (err) {
|
|
console.error("Duplicate failed:", err)
|
|
alert("Duplicate failed. Check console.")
|
|
}
|
|
}
|
|
|
|
async function handleTogglePublished() {
|
|
if (!page) return
|
|
try {
|
|
const updated = await pb.collection("pages").update<PbPage>(page.id, {
|
|
published: !page.published,
|
|
})
|
|
setPage(updated)
|
|
} catch (err) {
|
|
console.error("Toggle published failed:", err)
|
|
alert("Toggle published failed. Check console.")
|
|
}
|
|
}
|
|
|
|
if (!authenticated) {
|
|
return <Login onLogin={() => setAuthenticated(true)} />
|
|
}
|
|
|
|
if (!slug) {
|
|
return (
|
|
<div className="app-message">
|
|
<p>Add <code>?page=slug</code> to the URL to edit a page.</p>
|
|
<button onClick={handleLogout}>Logout</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (loading) {
|
|
return <div className="app-message">Loading...</div>
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<div className="app-message">
|
|
<p className="app-error">{error}</p>
|
|
<button onClick={handleLogout}>Logout</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!page) {
|
|
return <div className="app-message">Loading...</div>
|
|
}
|
|
|
|
return (
|
|
<div className="app">
|
|
<header className="app-header">
|
|
<span className="app-title">{page.title}</span>
|
|
<span className="app-slug">/{page.slug}</span>
|
|
<label className="app-published-toggle">
|
|
<input
|
|
type="checkbox"
|
|
checked={page.published}
|
|
onChange={handleTogglePublished}
|
|
/>
|
|
Published
|
|
</label>
|
|
<button onClick={handleDuplicate}>Duplicate</button>
|
|
<button onClick={handleLogout}>Logout</button>
|
|
</header>
|
|
<main className="app-main">
|
|
<Editor page={page} />
|
|
</main>
|
|
</div>
|
|
)
|
|
}
|