Skip to content

Commit

Permalink
refactor tagLabels logic into a util function
Browse files Browse the repository at this point in the history
  • Loading branch information
tinuola committed Nov 14, 2024
1 parent e46d051 commit a4b2a1f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
22 changes: 5 additions & 17 deletions pages/events/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import removeTags from '../utils/removeTags'
import { useContentIndexer } from '~/composables/useContentIndexer'
// UTILS
import { getEventFilterLabels } from '~/utils/getEventFilterLabels'
const { $graphql } = useNuxtApp()
Expand Down Expand Up @@ -128,24 +129,11 @@ const parsedFTVAEventScreeningDetails = computed(() => {
})
})
// Extract tag labels from event filters
const parsedTagLabels = computed(() => {
if (!page.value.ftvaEventTypeFilters && !page.value.ftvaScreeningFormatFilters) {
return []
}
const parsedLabels = []
const typeFilters = page.value.ftvaEventTypeFilters
const formatFilters = page.value.ftvaScreeningFormatFilters
if (typeFilters.length) {
typeFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}
if (formatFilters.length) {
formatFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}
return parsedLabels
const eventObj = page.value
const parsedTagLabels = getEventFilterLabels(eventObj)
return parsedTagLabels
})
useHead({
Expand Down
27 changes: 5 additions & 22 deletions pages/series/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import _get from 'lodash/get'
// GQL
import FTVAEventSeriesDetail from '../gql/queries/FTVAEventSeriesDetail.gql'
// UTIL
import { getEventFilterLabels } from '~/utils/getEventFilterLabels'
// COMPOSABLE
import { useContentIndexer } from '~/composables/useContentIndexer'
import removeTags from '~/utils/removeTags'
Expand Down Expand Up @@ -98,7 +101,7 @@ const parsedUpcomingEvents = computed(() => {
// Transform data
return upcomingEvents.value.map((item, index) => {
const parsedTagLabels = getParsedTagLabels(item)
const parsedTagLabels = getEventFilterLabels(item)
return {
...item,
Expand All @@ -116,7 +119,7 @@ const parsedPastEvents = computed(() => {
// Transform data
return pastEvents.value.map((item, index) => {
const parsedTagLabels = getParsedTagLabels(item)
const parsedTagLabels = getEventFilterLabels(item)
return {
...item,
Expand All @@ -127,26 +130,6 @@ const parsedPastEvents = computed(() => {
})
})
function getParsedTagLabels(obj) {
if (!obj.ftvaEventTypeFilters && !obj.ftvaScreeningFormatFilters) {
return []
}
const parsedLabels = []
const typeFilters = obj.ftvaEventTypeFilters
const formatFilters = obj.ftvaScreeningFormatFilters
if (typeFilters.length) {
typeFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}
if (formatFilters.length) {
formatFilters.forEach(obj => parsedLabels.push({ title: obj.title }))
}
return parsedLabels
}
// If no Upcoming Events, set starting tab to Past Events
const parsedInitialTabIndex = computed(() => {
if (parsedUpcomingEvents.value.length === 0) {
Expand Down
28 changes: 28 additions & 0 deletions utils/getEventFilterLabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Extract tag labels from FTVA filters (ftvaScreeningFormatFilters,
ftvaEventTypeFilters) and return as a single array
* @param {Object}
* @returns {Array}
*/

export function getEventFilterLabels(obj) {
if (!obj.ftvaEventTypeFilters && !obj.ftvaScreeningFormatFilters) {
return []
}

const parsedTagLabels = []

const eventTypeFilters = obj.ftvaEventTypeFilters
const screeningFormatFilters = obj.ftvaScreeningFormatFilters

if (eventTypeFilters.length) {
eventTypeFilters.forEach(obj => parsedTagLabels.push({ title: obj.title }))
}

if (screeningFormatFilters.length) {
screeningFormatFilters.forEach(obj => parsedTagLabels.push({ title: obj.title }))
}

return parsedTagLabels
}

0 comments on commit a4b2a1f

Please sign in to comment.