diff --git a/src/components/PreviewCard.tsx b/src/components/PreviewCard.tsx index 010690d..e38d291 100644 --- a/src/components/PreviewCard.tsx +++ b/src/components/PreviewCard.tsx @@ -28,7 +28,7 @@ interface Props { topChips?: string[]; bottomChips?: string[]; keepInfoVisible?: boolean; - stackEffect?: boolean; + stackNumber?: number; metadata?: { currencies?: AppStaticProps["currencies"]; release_date?: DatePickerFragment | null; @@ -53,7 +53,7 @@ export function PreviewCard(props: Immutable): JSX.Element { title, subtitle, description, - stackEffect = false, + stackNumber = 0, topChips, bottomChips, keepInfoVisible, @@ -117,20 +117,27 @@ export function PreviewCard(props: Immutable): JSX.Element { hover:[--play-opacity:100] transition-transform [--stacked-top:0] hover:[--stacked-top:1]" > - {thumbnail && stackEffect && ( + {thumbnail && stackNumber > 0 && ( <> - + +
+ +
)} @@ -145,6 +152,14 @@ export function PreviewCard(props: Immutable): JSX.Element { image={thumbnail} quality={ImageQuality.Medium} /> + {stackNumber > 0 && ( +
+ {stackNumber} +
+ )} {hoverlay && hoverlay.__typename === "Video" && ( <>
["data"] + >["attributes"] + >["contents"] + >["data"] + >, + currentSlug: string +) { + for (let index = 0; index < group.length; index += 1) { + const content = group[index]; + if (content.attributes?.slug === currentSlug && index > 0) { + return group[index - 1]; + } + } + return undefined; +} + +function getNextContent( + group: Immutable< + NonNullable< + NonNullable< + NonNullable< + NonNullable["data"] + >["attributes"] + >["contents"] + >["data"] + >, + currentSlug: string +) { + for (let index = 0; index < group.length; index += 1) { + const content = group[index]; + if (content.attributes?.slug === currentSlug && index < group.length - 1) { + return group[index + 1]; + } + } + return undefined; +} + export default function Content(props: Immutable): JSX.Element { const { langui, content, languages } = props; const isMobile = useMediaMobile(); @@ -44,6 +86,17 @@ export default function Content(props: Immutable): JSX.Element { languageExtractor: (item) => item.language?.data?.attributes?.code, }); + const previousContent = content.group?.data?.attributes?.contents + ? getPreviousContent( + content.group.data.attributes.contents.data, + content.slug + ) + : undefined; + + const nextContent = content.group?.data?.attributes?.contents + ? getNextContent(content.group.data.attributes.contents.data, content.slug) + : undefined; + const subPanel = ( ): JSX.Element { languageSwitcher={} /> - {content.previous_recommended?.data?.attributes && ( + {previousContent?.attributes && (

Previous content

): JSX.Element { bottomChips={ isMobile ? undefined - : content.previous_recommended.data.attributes.categories?.data.map( + : previousContent.attributes.categories?.data.map( (category) => category.attributes?.short ?? "" ) } @@ -265,43 +313,30 @@ export default function Content(props: Immutable): JSX.Element { - {content.next_recommended?.data?.attributes && ( + {nextContent?.attributes && ( <>

Follow-up content

): JSX.Element { bottomChips={ isMobile ? undefined - : content.next_recommended.data.attributes.categories?.data.map( + : nextContent.attributes.categories?.data.map( (category) => category.attributes?.short ?? "" ) } diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx index 1ccb40a..0591088 100644 --- a/src/pages/contents/index.tsx +++ b/src/pages/contents/index.tsx @@ -18,7 +18,7 @@ import { GetStaticPropsContext } from "next"; import { useEffect, useState } from "react"; interface Props extends AppStaticProps { - contents: Exclude["data"]; + contents: NonNullable["data"]; } type GroupContentItems = Map>; @@ -119,11 +119,12 @@ export default function Contents(props: Immutable): JSX.Element { subtitle={item.attributes.translations?.[0]?.subtitle} thumbnail={item.attributes.thumbnail?.data?.attributes} thumbnailAspectRatio="3/2" - stackEffect={ - item.attributes.next_recommended?.data?.id !== null && - item.attributes.next_recommended?.data?.id !== - undefined && - combineRelatedContent + stackNumber={ + combineRelatedContent && + item.attributes.group?.data?.attributes?.combine + ? item.attributes.group?.data?.attributes.contents + ?.data.length + : 0 } topChips={ item.attributes.type?.data?.attributes @@ -263,7 +264,11 @@ function filterContents( ): Immutable { if (combineRelatedContent) { return [...contents].filter( - (content) => !content.attributes?.previous_recommended?.data?.id + (content) => + !content.attributes?.group?.data?.attributes || + !content.attributes.group.data.attributes.combine || + content.attributes.group.data.attributes.contents?.data?.[0].id === + content.id ); } return contents;