Load draft content in admin while keeping public lesson locks

This commit is contained in:
nmemmert
2026-05-12 15:23:17 -04:00
parent da35006a30
commit dba5f16bcd
2 changed files with 48 additions and 3 deletions
+16 -2
View File
@@ -119,19 +119,33 @@ function isSectionReleased(section) {
return releaseTime <= Date.now() return releaseTime <= Date.now()
} }
function redactUnreleasedSection(section) {
if (!section || typeof section !== 'object') return section
if (isSectionReleased(section)) return section
return {
...section,
passageText: '',
commentary: '',
greekNotes: [],
studyQuestions: [],
audioEmbedUrl: '',
}
}
function filterSiteContentByReleaseDate(siteContent) { function filterSiteContentByReleaseDate(siteContent) {
if (!siteContent || typeof siteContent !== 'object' || Array.isArray(siteContent)) return siteContent if (!siteContent || typeof siteContent !== 'object' || Array.isArray(siteContent)) return siteContent
const filteredStudies = Array.isArray(siteContent.studies) const filteredStudies = Array.isArray(siteContent.studies)
? siteContent.studies.map(study => { ? siteContent.studies.map(study => {
if (!study || typeof study !== 'object') return study if (!study || typeof study !== 'object') return study
const sections = Array.isArray(study.sections) ? study.sections.filter(isSectionReleased) : [] const sections = Array.isArray(study.sections) ? study.sections.map(redactUnreleasedSection) : []
return { ...study, sections } return { ...study, sections }
}) })
: siteContent.studies : siteContent.studies
const filteredLegacySections = Array.isArray(siteContent.colossiansStudySections) const filteredLegacySections = Array.isArray(siteContent.colossiansStudySections)
? siteContent.colossiansStudySections.filter(isSectionReleased) ? siteContent.colossiansStudySections.map(redactUnreleasedSection)
: siteContent.colossiansStudySections : siteContent.colossiansStudySections
return { return {
+32 -1
View File
@@ -1615,6 +1615,7 @@ function LegalPage({ title, body }: { title: string; body: string[] }) {
function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: SiteContent) => void }) { function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: SiteContent) => void }) {
const [status, setStatus] = useState<'checking' | 'authenticated' | 'unauthenticated' | 'misconfigured'>('checking') const [status, setStatus] = useState<'checking' | 'authenticated' | 'unauthenticated' | 'misconfigured'>('checking')
const [adminContent, setAdminContent] = useState<SiteContent>(content)
const [password, setPassword] = useState('') const [password, setPassword] = useState('')
const [errorMsg, setErrorMsg] = useState('') const [errorMsg, setErrorMsg] = useState('')
const [submitting, setSubmitting] = useState(false) const [submitting, setSubmitting] = useState(false)
@@ -1639,6 +1640,36 @@ function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: Sit
}) })
}, []) }, [])
useEffect(() => {
if (status === 'authenticated') return
setAdminContent(content)
}, [content, status])
useEffect(() => {
if (status !== 'authenticated') return
let cancelled = false
fetch('/api/admin-content?source=draft')
.then(r => (r.ok ? r.json() : null))
.then(data => {
if (cancelled) return
if (data?.siteContent) {
setAdminContent(c => ({ ...c, ...data.siteContent }))
}
})
.catch(() => {})
return () => {
cancelled = true
}
}, [status])
function handleAdminSave(next: SiteContent) {
setAdminContent(next)
onSave(next)
}
async function handleLogin(e: React.FormEvent) { async function handleLogin(e: React.FormEvent) {
e.preventDefault() e.preventDefault()
setSubmitting(true) setSubmitting(true)
@@ -1714,7 +1745,7 @@ function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: Sit
} }
if (status === 'authenticated') { if (status === 'authenticated') {
return <AdminPage content={content} onSave={onSave} onLogout={handleLogout} /> return <AdminPage content={adminContent} onSave={handleAdminSave} onLogout={handleLogout} />
} }
return ( return (