From 7286ba70dc28f5c2b6e5264e0eea445a0cef0c9b Mon Sep 17 00:00:00 2001 From: Diptesh Choudhuri Date: Mon, 1 Jul 2024 12:21:55 +0530 Subject: [PATCH] feat(frontend): revamp episode experience --- .../_dashboard.media.item.$id._index.tsx | 204 ++++++++++-------- 1 file changed, 114 insertions(+), 90 deletions(-) diff --git a/apps/frontend/app/routes/_dashboard.media.item.$id._index.tsx b/apps/frontend/app/routes/_dashboard.media.item.$id._index.tsx index 80a175bd72..a607089eaf 100644 --- a/apps/frontend/app/routes/_dashboard.media.item.$id._index.tsx +++ b/apps/frontend/app/routes/_dashboard.media.item.$id._index.tsx @@ -1,3 +1,4 @@ +import { useAutoAnimate } from "@formkit/auto-animate/react"; import { $path } from "@ignisda/remix-routes"; import { ActionIcon, @@ -68,7 +69,7 @@ import { IconX, } from "@tabler/icons-react"; import type { HumanizeDurationOptions } from "humanize-duration-ts"; -import { type ReactNode, useState } from "react"; +import { Fragment, type ReactNode, useState } from "react"; import { GroupedVirtuoso, Virtuoso } from "react-virtuoso"; import { namedAction } from "remix-utils/named-action"; import invariant from "tiny-invariant"; @@ -1240,94 +1241,6 @@ const MergeMetadataModal = (props: { ); }; -const DisplaySeasonOrEpisodeDetails = (props: { - name: string; - children: ReactNode; - runtime?: number | null; - overview?: string | null; - displayIndicator: number; - id?: number | string | null; - numEpisodes?: number | null; - posterImages: Array; - publishDate?: string | null; - isEpisode?: boolean; -}) => { - const display = [ - props.runtime - ? humanizeDuration( - dayjsLib.duration(props.runtime, "minutes").asMilliseconds(), - { units: ["h", "m"] }, - ) - : null, - props.publishDate ? dayjsLib(props.publishDate).format("ll") : null, - props.numEpisodes ? `${props.numEpisodes} episodes` : null, - ] - .filter(Boolean) - .join("; "); - - const isSeen = props.displayIndicator >= 1; - - const DisplayDetails = () => ( - <> - {props.name} - {display ? ( - - {display} - - ) : null} - - ); - - return ( - - - - - - - - - - - - {props.children} - - - - - - {props.overview ? ( - - ) : null} - - ); -}; - type History = UserMetadataDetailsQuery["userMetadataDetails"]["history"][number]; @@ -1479,6 +1392,117 @@ const SeenItem = (props: { history: History; index: number }) => { ); }; +const DisplaySeasonOrEpisodeDetails = (props: { + name: string; + children: ReactNode; + runtime?: number | null; + overview?: string | null; + displayIndicator: number; + id?: number | string | null; + numEpisodes?: number | null; + posterImages: Array; + publishDate?: string | null; + isShowSeason?: boolean; +}) => { + const [parent] = useAutoAnimate(); + const [displayOverview, setDisplayOverview] = useDisclosure(false); + const swt = (t: string) => ( + + {t} + + ); + const filteredElements = [ + props.runtime + ? swt( + humanizeDuration( + dayjsLib.duration(props.runtime, "minutes").asMilliseconds(), + { units: ["h", "m"] }, + ), + ) + : null, + props.publishDate ? swt(dayjsLib(props.publishDate).format("ll")) : null, + props.numEpisodes ? swt(`${props.numEpisodes} episodes`) : null, + props.overview ? ( + + {displayOverview ? "Hide" : "Show"} overview + + ) : null, + ].filter((s) => s !== null); + const display = + filteredElements.length > 0 + ? filteredElements + .map((s, i) => {s}) + .reduce((prev, curr) => [prev, " • ", curr]) + : null; + + const isSeen = props.displayIndicator >= 1; + + const DisplayDetails = () => ( + <> + {props.name} + {display ? ( + + {display} + + ) : null} + + ); + + return ( + + + + + + + + + + + + + {props.children} + + + + + + {props.overview && displayOverview ? ( + + ) : null} + + + ); +}; + const DisplayShowSeason = (props: { seasonIdx: number; showProgress: UserMetadataDetailsQuery["userMetadataDetails"]["showProgress"]; @@ -1502,6 +1526,7 @@ const DisplayShowSeason = (props: { runtime={season.episodes .map((e) => e.runtime || 0) .reduce((i, a) => i + a, 0)} + isShowSeason > <> {season.episodes.length > 0 ? ( @@ -1553,7 +1578,6 @@ const DisplayShowEpisode = (props: { name={`${episode.episodeNumber}. ${episode.name}`} publishDate={episode.publishDate} displayIndicator={numTimesEpisodeSeen} - isEpisode >