diff --git a/pages/index.vue b/pages/index.vue index edc42a8..5e28ac8 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -57,16 +57,24 @@

Use the dropdown below to view a previous sermon

- +
+ + +
@@ -82,34 +90,36 @@ const { data: authData } = await useFetch('/api/auth/verify') const isAuthenticated = computed(() => authData.value?.authenticated || false) -// Fetch non-archived sermons only -const { data: allSermons } = await useFetch('/api/sermons?includeArchived=false') +// Fetch non-archived sermons for the most recent sermon +const { data: activeSermons } = await useFetch('/api/sermons?includeArchived=false') + +// Fetch archived sermons for the previous sermons dropdown +const { data: archivedSermons } = await useFetch('/api/sermons?includeArchived=true') const selectedSermonSlug = ref('') -// Get most recent sermon +// Get most recent non-archived sermon const mostRecentSermon = computed(() => { - if (!allSermons.value || allSermons.value.length === 0) return null - return allSermons.value[0] + if (!activeSermons.value || activeSermons.value.length === 0) return null + return activeSermons.value[0] }) -// Get all previous sermons (excluding the most recent) +// Get archived sermons only for the previous sermons dropdown const previousSermons = computed(() => { - if (!allSermons.value || allSermons.value.length <= 1) return [] - return allSermons.value.slice(1) + if (!archivedSermons.value) return [] + return archivedSermons.value.filter((s: any) => s.archived === 1) }) // Check if most recent sermon is today const sermonHeading = computed(() => { if (!mostRecentSermon.value) return 'Recent Sermon' - const sermonDate = new Date(mostRecentSermon.value.date) + const sermonDate = new Date(mostRecentSermon.value.date + 'T00:00:00') const today = new Date() + today.setHours(0, 0, 0, 0) + sermonDate.setHours(0, 0, 0, 0) - // Compare dates (ignoring time) - const isToday = sermonDate.getFullYear() === today.getFullYear() && - sermonDate.getMonth() === today.getMonth() && - sermonDate.getDate() === today.getDate() + const isToday = sermonDate.getTime() === today.getTime() return isToday ? "Today's Sermon" : 'Most Recent Sermon' })