diff --git a/components/SermonCard.vue b/components/SermonCard.vue index 8283f07..3167fa9 100644 --- a/components/SermonCard.vue +++ b/components/SermonCard.vue @@ -2,7 +2,7 @@

{{ sermon.title }}

-

{{ formatDate(sermon.date) }}

+

{{ formatDate(sermon.displayDate || sermon.date) }}

{ const today = new Date() today.setHours(0, 0, 0, 0) - return activeSermons.value.filter((s: any) => { - // Check primary date - const sermonDate = new Date(s.date + 'T00:00:00') - sermonDate.setHours(0, 0, 0, 0) - if (sermonDate.getTime() > today.getTime()) return true - - // Check additional dates if they exist - if (s.dates) { - try { - const additionalDates = JSON.parse(s.dates) - return additionalDates.some((dateStr: string) => { - const additionalDate = new Date(dateStr + 'T00:00:00') - additionalDate.setHours(0, 0, 0, 0) - return additionalDate.getTime() > today.getTime() - }) - } catch { - return false + return activeSermons.value + .map((s: any) => { + // Check primary date + const sermonDate = new Date(s.date + 'T00:00:00') + sermonDate.setHours(0, 0, 0, 0) + + // If primary date is in the future, use it + if (sermonDate.getTime() > today.getTime()) { + return { ...s, displayDate: s.date } } - } - - return false - }) + + // Check additional dates if they exist + if (s.dates) { + try { + const additionalDates = JSON.parse(s.dates) + // Find the first future date from additional dates + const futureDate = additionalDates.find((dateStr: string) => { + const additionalDate = new Date(dateStr + 'T00:00:00') + additionalDate.setHours(0, 0, 0, 0) + return additionalDate.getTime() > today.getTime() + }) + + if (futureDate) { + return { ...s, displayDate: futureDate } + } + } catch { + return null + } + } + + return null + }) + .filter((s: any) => s !== null) }) // Get archived sermons only for the previous sermons dropdown