Load draft content in admin while keeping public lesson locks
This commit is contained in:
@@ -119,19 +119,33 @@ function isSectionReleased(section) {
|
||||
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) {
|
||||
if (!siteContent || typeof siteContent !== 'object' || Array.isArray(siteContent)) return siteContent
|
||||
|
||||
const filteredStudies = Array.isArray(siteContent.studies)
|
||||
? siteContent.studies.map(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 }
|
||||
})
|
||||
: siteContent.studies
|
||||
|
||||
const filteredLegacySections = Array.isArray(siteContent.colossiansStudySections)
|
||||
? siteContent.colossiansStudySections.filter(isSectionReleased)
|
||||
? siteContent.colossiansStudySections.map(redactUnreleasedSection)
|
||||
: siteContent.colossiansStudySections
|
||||
|
||||
return {
|
||||
|
||||
+32
-1
@@ -1615,6 +1615,7 @@ function LegalPage({ title, body }: { title: string; body: string[] }) {
|
||||
|
||||
function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: SiteContent) => void }) {
|
||||
const [status, setStatus] = useState<'checking' | 'authenticated' | 'unauthenticated' | 'misconfigured'>('checking')
|
||||
const [adminContent, setAdminContent] = useState<SiteContent>(content)
|
||||
const [password, setPassword] = useState('')
|
||||
const [errorMsg, setErrorMsg] = useState('')
|
||||
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) {
|
||||
e.preventDefault()
|
||||
setSubmitting(true)
|
||||
@@ -1714,7 +1745,7 @@ function AdminShell({ content, onSave }: { content: SiteContent; onSave: (c: Sit
|
||||
}
|
||||
|
||||
if (status === 'authenticated') {
|
||||
return <AdminPage content={content} onSave={onSave} onLogout={handleLogout} />
|
||||
return <AdminPage content={adminContent} onSave={handleAdminSave} onLogout={handleLogout} />
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user