Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use of .sort() in Podcast templates #618

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
:initial-slide="
activeSeasonId === initialSeasonId && initialEpisodeIndex ? initialEpisodeIndex : 0
"
:slides="activeTabData.episodes"
:slides="activeTabData.episodes as Partial<Slide>[]"
/>
</keep-alive>
</div>
Expand All @@ -61,9 +61,10 @@ import ThumbnailCarousel from './../ThumbnailCarousel/ThumbnailCarousel.vue'

const route = useRoute()

interface ActiveTab {
interface Slide {
url: string
title: string
episodes: Episode[]
thumbnailImage: Partial<ImageObject>
}

interface Episode {
Expand All @@ -72,19 +73,25 @@ interface Episode {
publicationDate: any
thumbnailImage: Partial<ImageObject>
}

interface ActiveTab {
title?: string
episodes?: Episode[] | Season
}

interface Season {
id: string
url: string
title: string
seasonNumber: number
episodes: Episode[]
url?: string
title?: string
seasonNumber?: number
episodes?: Episode[]
}

interface Series {
id: string
title: string
url: string
seasons: Season[]
title?: string
url?: string
seasons?: Season[]
}
export default defineComponent({
name: 'PodcastSeriesCarousel',
Expand All @@ -111,11 +118,17 @@ export default defineComponent({
}
},
computed: {
sortedSeasons(): Season[] | null {
let seasons = null
sortedSeasons(): Season[] | undefined {
let seasons = undefined
if (this.series && this.series.seasons) {
seasons = this.series.seasons
return seasons.sort((a: Season, b: Season) => a.seasonNumber - b.seasonNumber)
// @ts-expect-error seasons is an array
seasons = seasons.toSorted((a: Season, b: Season) => {
if (a.seasonNumber && b.seasonNumber) {
return a.seasonNumber - b.seasonNumber
}
})
return seasons
}
return seasons
},
Expand All @@ -142,24 +155,31 @@ export default defineComponent({
}
return null
},
activeTabData(): ActiveTab | undefined {
let season: Season | undefined = undefined
if (this.series?.seasons) {
activeTabData(): ActiveTab | Season | undefined {
let season
if (this.series?.seasons?.length) {
if (this.activeSeasonId) {
season = this.series.seasons.find((o: Season) => {
return o.id === this.activeSeasonId
})
} else {
season = this.series.seasons[0]
}
if (season?.episodes) {
season.episodes.sort(
(a: Episode, b: Episode) =>
new Date(a.publicationDate).getTime() - new Date(b.publicationDate).getTime()
)
if (season?.episodes?.length) {
let episodes: Episode[] = season.episodes
// @ts-expect-error episodes is an array
episodes = episodes.toSorted((a: Episode, b: Episode) => {
if (a.publicationDate && b.publicationDate) {
return new Date(a.publicationDate).getTime() - new Date(b.publicationDate).getTime()
}
})
season = {
...season,
episodes: episodes
}
}
}
return season ? season : undefined
return season
}
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
</LayoutHelper>

<PodcastSeriesCarousel
v-if="data?.series"
:series="data.series"
:initial-season-id="data.parent ? data.parent.id : null"
class="mb-12 lg:mb-24"
Expand Down
49 changes: 13 additions & 36 deletions packages/vue/src/templates/PageImageDetail/PageImageDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@
</LayoutHelper>
<LayoutHelper
v-if="
(data.keepExploringMission && data.keepExploringMission.length) ||
(data.keepExploringTarget && data.keepExploringTarget.length) ||
(data.keepExploringInstrument && data.keepExploringInstrument.length)
data.keepExploringMission?.length ||
data.keepExploringTarget?.length ||
data.keepExploringInstrument?.length
"
indent="col-2"
>
Expand All @@ -228,12 +228,7 @@
</h2>
<ul class="TopicTabs flex flex-row flex-wrap justify-start pb-4 mb-5 list-none">
<li
v-if="
data.relatedMission &&
data.relatedMission.length &&
data.keepExploringMission &&
data.keepExploringMission.length
"
v-if="data.relatedMission?.length && data.keepExploringMission?.length"
class="last:mr-0 sm:w-auto md:mr-16 w-full mr-10 text-center"
>
<button
Expand All @@ -247,12 +242,7 @@
</button>
</li>
<li
v-if="
data.targets &&
data.targets.length &&
data.keepExploringTarget &&
data.keepExploringTarget.length
"
v-if="data.targets?.length && data.keepExploringTarget?.length"
class="last:mr-0 sm:w-auto md:mr-16 w-full mr-10 text-center"
>
<button
Expand All @@ -265,12 +255,7 @@
</button>
</li>
<li
v-if="
data.instruments &&
data.instruments.length &&
data.keepExploringInstrument &&
data.keepExploringInstrument.length
"
v-if="data.instruments?.length && data.keepExploringInstrument?.length"
class="last:mr-0 sm:w-auto md:mr-16 w-full mr-10 text-center"
>
<button
Expand All @@ -285,31 +270,23 @@
</ul>
</LayoutHelper>
<keep-alive>
<template
v-if="openTab === 1 && data.keepExploringMission && data.keepExploringMission.length"
>
<template v-if="openTab === 1 && data.keepExploringMission?.length">
<ThumbnailCarousel
:key="openTab"
class="lg:mb-24 mb-12"
:aria-hidden="openTab === 1 ? 'false' : 'true'"
:slides="data.keepExploringMission"
/>
</template>
<template
v-else-if="openTab === 2 && data.keepExploringTarget && data.keepExploringTarget.length"
>
<template v-else-if="openTab === 2 && data.keepExploringTarget?.length">
<ThumbnailCarousel
:key="openTab"
class="lg:mb-24 mb-12"
:aria-hidden="openTab === 2 ? 'false' : 'true'"
:slides="data.keepExploringTarget"
/>
</template>
<template
v-else-if="
openTab === 3 && data.keepExploringInstrument && data.keepExploringInstrument.length
"
>
<template v-else-if="openTab === 3 && data.keepExploringInstrument?.length">
<ThumbnailCarousel
:key="openTab"
class="lg:mb-24 mb-12"
Expand All @@ -319,7 +296,7 @@
</template>
</keep-alive>
<div
v-if="data.relatedTopics && data.relatedTopics.length"
v-if="data.relatedTopics?.length"
class="bg-gray-light lg:py-24 py-12"
>
<BlockLinkCarousel
Expand Down Expand Up @@ -386,11 +363,11 @@ export default defineComponent({
methods: {
initExploreCarousels() {
if (this.data) {
if (this.data.keepExploringMission && this.data.keepExploringMission.length) {
if (this.data.keepExploringMission?.length) {
this.openTab = 1
} else if (this.data.keepExploringTarget && this.data.keepExploringTarget.length) {
} else if (this.data.keepExploringTarget?.length) {
this.openTab = 2
} else if (this.data.keepExploringInstrument && this.data.keepExploringInstrument.length) {
} else if (this.data.keepExploringInstrument?.length) {
this.openTab = 3
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/templates/www/PagePodcast/PagePodcast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ export default defineComponent({
return this.defaultShowGridView
},
sortedSeasons() {
let seasons = null
let seasons = undefined
if (this.data && this.data.seasons) {
seasons = this.data.seasons
return seasons.sort((a, b) => a.seasonNumber - b.seasonNumber)
seasons = seasons.toSorted((a, b) => a.seasonNumber - b.seasonNumber)
}
return seasons
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2021", "DOM", "DOM.Iterable"],
"lib": ["ES2021", "DOM", "DOM.Iterable", "ESNext.Array"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down