From 9e90d81e2c5462aef5852a95491db668e842054a Mon Sep 17 00:00:00 2001 From: Carey P Gumaer Date: Wed, 22 Jan 2025 15:09:40 -0500 Subject: [PATCH] drawer v2 podcast carousels (#1981) * refactor carousel building * add "other episodes in this podcast" and "episodes in this podcast" carousels * title should be "Recent Episodes" --- .../LearningResourceDrawerV2.test.tsx | 3 +- .../LearningResourceDrawerV2.tsx | 110 ++++++++---------- 2 files changed, 52 insertions(+), 61 deletions(-) diff --git a/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.test.tsx b/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.test.tsx index 5635af0341..d6217dfb67 100644 --- a/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.test.tsx +++ b/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.test.tsx @@ -64,7 +64,8 @@ describe("LearningResourceDrawerV2", () => { if ( resource.resource_type === ResourceTypeEnum.Program || - resource.resource_type === ResourceTypeEnum.VideoPlaylist + resource.resource_type === ResourceTypeEnum.VideoPlaylist || + resource.resource_type === ResourceTypeEnum.Podcast ) { const items = factories.learningResources.resources({ count: 10, diff --git a/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.tsx b/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.tsx index b71f31c30b..ea9405a9ce 100644 --- a/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.tsx +++ b/frontends/main/src/page-components/LearningResourceDrawer/LearningResourceDrawerV2.tsx @@ -104,77 +104,33 @@ const DrawerContent: React.FC<{ } }, [user]) useCapturePageView(Number(resourceId)) - const coursesInProgramCarousel = - resource.data?.resource_type === ResourceTypeEnum.Program ? ( + const itemsCarousel = ( + title: string, + learningResourceId: number, + excludeResourceId: number, + ) => { + return ( - ) : null - const topCarousels = coursesInProgramCarousel - ? [coursesInProgramCarousel] - : undefined - const otherVideosInThisSeries = - resource.data?.resource_type === ResourceTypeEnum.Video ? ( - resource.data?.playlists?.length > 0 ? ( - - ) : null - ) : null - const videosInThisPlaylist = - resource.data?.resource_type === ResourceTypeEnum.VideoPlaylist ? ( - - ) : null + ) + } const similarResourcesCarousel = ( )) + const topCarousels = [] + if (resource.data?.resource_type === ResourceTypeEnum.Program) { + topCarousels.push( + itemsCarousel("Courses in this Program", resourceId, resourceId), + ) + } const bottomCarousels = [] - if (otherVideosInThisSeries) { - bottomCarousels.push(otherVideosInThisSeries) + if ( + resource.data?.resource_type === ResourceTypeEnum.Video && + resource.data?.playlists?.length > 0 + ) { + bottomCarousels.push( + itemsCarousel( + "Other Videos in this Series", + parseInt(resource.data.playlists[0]), + resourceId, + ), + ) + } + if (resource.data?.resource_type === ResourceTypeEnum.VideoPlaylist) { + bottomCarousels.push( + itemsCarousel("Videos in this Series", resourceId, resourceId), + ) + } + if ( + resource.data?.resource_type === ResourceTypeEnum.PodcastEpisode && + resource.data?.podcast_episode?.podcasts?.length > 0 + ) { + bottomCarousels.push( + itemsCarousel( + "Other Episodes in this Podcast", + parseInt(resource.data.podcast_episode.podcasts[0]), + resourceId, + ), + ) } - if (videosInThisPlaylist) { - bottomCarousels.push(videosInThisPlaylist) + if (resource.data?.resource_type === ResourceTypeEnum.Podcast) { + bottomCarousels.push( + itemsCarousel("Recent Episodes", resourceId, resourceId), + ) } bottomCarousels.push(similarResourcesCarousel) bottomCarousels.push(...(topicCarousels || []))