Generalize study release-date gating across all studies
This commit is contained in:
+27
-10
@@ -97,31 +97,47 @@ function getChapterSummaries(study: StudyProgram) {
|
||||
})
|
||||
}
|
||||
|
||||
function getSectionReleaseDate(section: StudySection): Date | null {
|
||||
const candidateValues = [
|
||||
section?.releasedAt,
|
||||
(section as StudySection & { releaseDate?: string }).releaseDate,
|
||||
(section as StudySection & { availableAt?: string }).availableAt,
|
||||
(section as StudySection & { publishAt?: string }).publishAt,
|
||||
]
|
||||
|
||||
for (const candidate of candidateValues) {
|
||||
if (typeof candidate !== 'string' || !candidate.trim()) continue
|
||||
const parsed = new Date(candidate)
|
||||
if (!Number.isNaN(parsed.getTime())) return parsed
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function isNewLesson(section: StudySection): boolean {
|
||||
if (!section.releasedAt) return false
|
||||
const releaseDate = new Date(section.releasedAt)
|
||||
const releaseDate = getSectionReleaseDate(section)
|
||||
if (!releaseDate) return false
|
||||
const now = new Date()
|
||||
const daysSinceRelease = (now.getTime() - releaseDate.getTime()) / (1000 * 60 * 60 * 24)
|
||||
return daysSinceRelease >= 0 && daysSinceRelease <= 14
|
||||
}
|
||||
|
||||
function isComingSoon(section: StudySection): boolean {
|
||||
if (!section.releasedAt) return false
|
||||
const releaseDate = new Date(section.releasedAt)
|
||||
const releaseDate = getSectionReleaseDate(section)
|
||||
if (!releaseDate) return false
|
||||
const now = new Date()
|
||||
return releaseDate > now
|
||||
}
|
||||
|
||||
function isSectionReleased(section: StudySection): boolean {
|
||||
if (!section.releasedAt) return false
|
||||
const releaseDate = new Date(section.releasedAt)
|
||||
if (Number.isNaN(releaseDate.getTime())) return false
|
||||
const releaseDate = getSectionReleaseDate(section)
|
||||
if (!releaseDate) return false
|
||||
return releaseDate <= new Date()
|
||||
}
|
||||
|
||||
function getReleaseDateDisplay(section: StudySection): string {
|
||||
if (!section.releasedAt) return ''
|
||||
const date = new Date(section.releasedAt)
|
||||
const date = getSectionReleaseDate(section)
|
||||
if (!date) return ''
|
||||
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })
|
||||
}
|
||||
|
||||
@@ -765,12 +781,13 @@ export function ColossiansStudySectionPage({ content }: Props) {
|
||||
}
|
||||
|
||||
if (!sectionIsReleased) {
|
||||
const releaseDateDisplay = getReleaseDateDisplay(section)
|
||||
return (
|
||||
<main className="thanks-page" aria-label="Lesson not yet available">
|
||||
<div className="thanks-card">
|
||||
<p className="eyebrow">{study.title}</p>
|
||||
<h1>Lesson Coming Soon</h1>
|
||||
<p>This lesson will be available on {getReleaseDateDisplay(section)}.</p>
|
||||
<p>{releaseDateDisplay ? `This lesson will be available on ${releaseDateDisplay}.` : 'This lesson will be available soon.'}</p>
|
||||
<Link to={`/study/${study.slug}`} className="btn-primary">Back to Lessons</Link>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user