diff --git a/src/components/PassengerShowcaseForm.js b/src/components/PassengerShowcaseForm.js index c4436b4f4..e8c619a6d 100644 --- a/src/components/PassengerShowcaseForm.js +++ b/src/components/PassengerShowcaseForm.js @@ -87,25 +87,23 @@ const useVideosWithShowcase = function () { return useMemo(() => { const tracks = data.tracks.nodes - .map((track) => { - // gather all videos from chapters (main track) - if (!track.videos && track.chapters) { - track.videos = track.chapters.flatMap((chapter) => chapter.videos); - } - delete track.chapters; - return track; - }) .map((track) => { // keep only videos that can be contributed to // keep only videos that belong to this track - track.videos = track.videos.filter( - (video) => - video.canContribute && video.canonicalTrack?.slug === track.slug - ); + const videoFilter = (video) => + video.canContribute && video.canonicalTrack?.slug === track.slug; + + track.videos = track.videos?.filter(videoFilter); + track.chapters = track.chapters + ?.map((chapter) => { + chapter.videos = chapter.videos.filter(videoFilter); + return chapter; + }) + .filter((chapter) => chapter.videos.length); return track; }) - .filter((track) => track.videos.length > 0); + .filter((track) => track.videos?.length || track.chapters?.length); // create a "challenges track" const challengesTrack = { @@ -211,6 +209,8 @@ const PassengerShowcaseForm = () => { }; }; + const selectedTrack = data.find((track) => track.slug === state.track); + return (