Fix admin publish data loss for unreleased lessons and harden data persistence
This commit is contained in:
+17
-6
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user