Fix admin publish data loss for unreleased lessons and harden data persistence

This commit is contained in:
nmemmert
2026-05-21 12:39:28 -04:00
parent da5f77c3c6
commit bd047b029c
4 changed files with 83 additions and 12 deletions
+17 -6
View File
@@ -691,11 +691,22 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
}
async function reloadContentFromServer() {
const r = await fetch('/api/admin-content')
if (!r.ok) return
const data = await r.json() as { siteContent?: Partial<SiteContent> }
if (data?.siteContent && typeof data.siteContent === 'object') {
const next = normalizeSiteContentForAdmin({ ...DEFAULTS, ...data.siteContent })
const draftRes = await fetch('/api/admin-content?source=draft')
if (draftRes.ok) {
const draftData = await draftRes.json() as { siteContent?: Partial<SiteContent> }
if (draftData?.siteContent && typeof draftData.siteContent === 'object') {
const next = normalizeSiteContentForAdmin({ ...DEFAULTS, ...draftData.siteContent })
setForm(next)
onSave(next)
return
}
}
const publishedRes = await fetch('/api/admin-content')
if (!publishedRes.ok) return
const publishedData = await publishedRes.json() as { siteContent?: Partial<SiteContent> }
if (publishedData?.siteContent && typeof publishedData.siteContent === 'object') {
const next = normalizeSiteContentForAdmin({ ...DEFAULTS, ...publishedData.siteContent })
setForm(next)
onSave(next)
}
@@ -771,7 +782,7 @@ export default function AdminPage({ content, onSave, onLogout }: Props) {
}
const published = await publishRes.json() as { publishedAt?: string }
const latestRes = await fetch('/api/admin-content')
const latestRes = await fetch('/api/admin-content?source=draft')
if (!latestRes.ok) throw new Error('Failed to refresh published content')
const latest = await latestRes.json() as { siteContent?: Partial<SiteContent> }
if (latest?.siteContent) {