Skip to content

Commit

Permalink
fix: APPS-2878 Show Only Upcoming Events in a Series (#25)
Browse files Browse the repository at this point in the history
* update gql query

* update series logic to only show upcoming events

---------

Co-authored-by: tinuola <tinuola@users.noreply.github.com>
  • Loading branch information
tinuola and tinuola authored Aug 9, 2024
1 parent 5b14501 commit b5d5021
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gql/queries/FTVAEventDetail.gql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ query FTVAEventDetail($slug: [String!]) {
slug
typeHandle
title
ftvaEvent {
ftvaEvent(startDateWithTime: ">= now") {
... on ftvaEvent_ftvaEvent_Entry {
id
to: slug
Expand Down
52 changes: 28 additions & 24 deletions pages/events/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const route = useRoute()
// DATA
const { data, error } = await useAsyncData(`events-detail-${route.params.slug}`, async () => {
const data = await $graphql.default.request(FTVAEventDetail, { slug: route.params.slug })
console.log('data', data)
return data
})
if (error.value) {
Expand All @@ -27,7 +26,6 @@ if (error.value) {
}
if (!data.value.ftvaEvent) {
// console.log('no data')
throw createError({
statusCode: 404,
statusMessage: 'Page Not Found',
Expand All @@ -48,6 +46,7 @@ watch(data, (newVal, oldVal) => {
const parsedImage = computed(() => {
return page.value.imageCarousel
})
// Transform data for Carousel
const parsedCarouselData = computed(() => {
// map image to item, map creditText to credit
Expand All @@ -61,25 +60,33 @@ const parsedCarouselData = computed(() => {
})
})
const pageId = computed(() => {
return page.value.id
})
const parsedFtvaEventSeries = computed(() => {
// const series = parsedFtvaEventSeries
const seriesEvents = series.value[0].ftvaEvent.map((obj) => {
return {
...obj,
image: obj.image[0]
}
})
/* Early Returns: If series.value is falsy or empty, or
if firstSeries.ftvaEvent is falsy or empty, return
an empty array immediately. */
if (!series.value || series.value.length === 0) {
return []
}
const [firstSeries] = series.value
if (!firstSeries.ftvaEvent || firstSeries.ftvaEvent.length === 0) {
return []
}
// Destructure each series item object and its image object
const seriesEvents = firstSeries.ftvaEvent.map(({ image, ...rest }) => ({
...rest,
image: image && image.length > 0 ? image[0] : null,
}))
const pageId = page.value.id
const events = seriesEvents.filter((item) => {
return item.id !== pageId // remove this page's event from the series list to avoid duplicate info
})
// return first 3 events
return events.slice(0, 3)
// Return series without the page's featured event
const filteredEvents = seriesEvents.filter(({ id }) => id !== pageId)
// Return first 3 events
return filteredEvents.slice(0, 3)
})
const parsedFTVAEventScreeningDetails = computed(() => {
Expand Down Expand Up @@ -177,23 +184,20 @@ const parsedFTVAEventScreeningDetails = computed(() => {
</div>
<div class="full-width">
<SectionWrapper
v-if="series && series.length > 0"
v-if="parsedFtvaEventSeries && parsedFtvaEventSeries.length > 0"
section-title="Upcoming events in this series"
theme="paleblue"
>
<SectionTeaserCard
v-if="series && series.length > 0"
v-if="parsedFtvaEventSeries && parsedFtvaEventSeries.length > 0"
:items="parsedFtvaEventSeries"
/>
</SectionWrapper>
</div>
</main>
</template>
<style
lang="scss"
scoped
>
<style lang="scss" scoped>
// VARS - TO DO move to global? reference tokens?
// WIDTH, HEIGHT, SPACING
$max-width: 1160px;
Expand Down

1 comment on commit b5d5021

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.