diff --git a/apps/admin/src/components/EditorShell.tsx b/apps/admin/src/components/EditorShell.tsx index 4e7d689..2d9a7b6 100644 --- a/apps/admin/src/components/EditorShell.tsx +++ b/apps/admin/src/components/EditorShell.tsx @@ -21,10 +21,10 @@ export default function EditorShell({ onLogout }: { onLogout?: () => void }) { if (savedId) { (async () => { try { - const res = await fetch(`/api/drafts/${savedId}`); + const res = await fetch(`/api/posts/${savedId}`); if (res.ok) { const data = await res.json(); - setDraft(data.content || ''); + setDraft(data.contentHtml || ''); setDraftId(data.id || savedId); } } catch {} @@ -32,10 +32,10 @@ export default function EditorShell({ onLogout }: { onLogout?: () => void }) { } (async () => { try { - const res = await fetch('/api/drafts'); + const res = await fetch('/api/posts'); if (res.ok) { const data = await res.json(); - if (Array.isArray(data.items)) setDrafts(data.items); + if (Array.isArray(data.items)) setDrafts(data.items.map((p: any) => p.id)); } } catch {} })(); @@ -45,10 +45,18 @@ export default function EditorShell({ onLogout }: { onLogout?: () => void }) { // Keep local fallback localStorage.setItem('voxblog_draft', draft); try { - const res = await fetch('/api/drafts', { + const res = await fetch('/api/posts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id: draftId ?? undefined, content: draft }), + body: JSON.stringify({ + id: draftId ?? undefined, + title: meta.title || undefined, + contentHtml: draft, + tags: meta.tagsText ? meta.tagsText.split(',').map(t => t.trim()).filter(Boolean) : undefined, + featureImage: meta.featureImage || undefined, + canonicalUrl: meta.canonicalUrl || undefined, + status: 'editing', + }), }); if (res.ok) { const data = await res.json(); @@ -62,13 +70,13 @@ export default function EditorShell({ onLogout }: { onLogout?: () => void }) { const loadDraft = async (id: string) => { try { - const res = await fetch(`/api/drafts/${id}`); + const res = await fetch(`/api/posts/${id}`); if (!res.ok) return; const data = await res.json(); - setDraft(data.content || ''); + setDraft(data.contentHtml || ''); setDraftId(data.id || id); localStorage.setItem('voxblog_draft_id', data.id || id); - if (data.content) localStorage.setItem('voxblog_draft', data.content); + if (data.contentHtml) localStorage.setItem('voxblog_draft', data.contentHtml); } catch {} }; @@ -78,9 +86,12 @@ export default function EditorShell({ onLogout }: { onLogout?: () => void }) { Welcome to VoxBlog Editor - setDraft(t)} /> + editorRef.current?.insertHtmlAtCursor(html)} + /> - Drafts + Posts {drafts.map(id => (