diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index d63d3a5..48eefa5 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -143,6 +143,7 @@ const PlayButton = ({ enableUserData: true, userId: userId, seasonId: item.SeasonId, + isMissing: false, // startItemId: item.Id, }); @@ -185,8 +186,8 @@ const PlayButton = ({ ], enableUserData: true, userId: userId, + isMissing: false, }); - console.log(result.data); if ( currentEpisodeId && result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) === diff --git a/src/routes/_api/episode/$id.tsx b/src/routes/_api/episode/$id.tsx index b2f728e..5d3c7ac 100644 --- a/src/routes/_api/episode/$id.tsx +++ b/src/routes/_api/episode/$id.tsx @@ -14,7 +14,10 @@ import { Blurhash } from "react-blurhash"; import useParallax from "@/utils/hooks/useParallax"; import { motion, useScroll } from "framer-motion"; -import { MediaStreamType } from "@jellyfin/sdk/lib/generated-client"; +import { + BaseItemKind, + MediaStreamType, +} from "@jellyfin/sdk/lib/generated-client"; import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; import { useQuery } from "@tanstack/react-query"; @@ -51,9 +54,12 @@ import sdrIcon from "@/assets/icons/sdr.svg"; import type MediaQualityInfo from "@/utils/types/mediaQualityInfo"; +import { Card } from "@/components/card/card"; +import CardScroller from "@/components/cardScroller/cardScroller"; import IconLink from "@/components/iconLink"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import { useCentralStore } from "@/utils/store/central"; +import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { Link, createFileRoute } from "@tanstack/react-router"; export const Route = createFileRoute("/_api/episode/$id")({ @@ -81,6 +87,22 @@ function EpisodeTitlePage() { refetchOnWindowFocus: true, }); + const upcomingEpisodes = useQuery({ + queryKey: ["item", id, "episode", "upcomingEpisodes"], + queryFn: async () => { + if (!api) return null; + const result = await getItemsApi(api).getItems({ + userId: user?.Id, + parentId: item.data?.ParentId ?? "", + startIndex: item.data?.IndexNumber ?? 0, + excludeLocationTypes: ["Virtual"], + }); + return result.data; + }, + enabled: item.isSuccess && item.data?.Type === BaseItemKind.Episode, + networkMode: "always", + }); + const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); const [selectedVideoTrack, setSelectedVideoTrack] = useState(0); @@ -748,7 +770,7 @@ function EpisodeTitlePage() { - {item.data.People?.length && ( + {(item.data.People?.length ?? 0) > 0 && (
Cast & Crew @@ -967,6 +989,30 @@ function EpisodeTitlePage() { )}
)} + + {upcomingEpisodes.isSuccess && + (upcomingEpisodes.data?.Items?.length ?? 0) > 0 && ( + + {upcomingEpisodes.data?.Items?.map((episode) => { + return ( + + ); + })} + + )} ); } diff --git a/src/routes/_api/series/$id.tsx b/src/routes/_api/series/$id.tsx index 2e6ae5c..2536af9 100644 --- a/src/routes/_api/series/$id.tsx +++ b/src/routes/_api/series/$id.tsx @@ -1,16 +1,10 @@ -import PropTypes from "prop-types"; -import React, { useState, useEffect, useLayoutEffect, useRef } from "react"; +import React, { useState, useEffect, useRef, useMemo } from "react"; import Box from "@mui/material/Box"; -import MuiCard from "@mui/material/Card"; -import CardContent from "@mui/material/CardContent"; -import CardMedia from "@mui/material/CardMedia"; import Chip from "@mui/material/Chip"; import CircularProgress from "@mui/material/CircularProgress"; import Divider from "@mui/material/Divider"; -import LinearProgress from "@mui/material/LinearProgress"; import MenuItem from "@mui/material/MenuItem"; -import Skeleton from "@mui/material/Skeleton"; import Stack from "@mui/material/Stack"; import TextField from "@mui/material/TextField"; import Typography from "@mui/material/Typography"; @@ -21,14 +15,9 @@ import { AnimatePresence, motion, useScroll } from "framer-motion"; import { Blurhash } from "react-blurhash"; -import { - BaseItemKind, - ItemFields, - LocationType, -} from "@jellyfin/sdk/lib/generated-client"; +import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api"; -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; import { useQuery } from "@tanstack/react-query"; @@ -63,29 +52,6 @@ import { useCentralStore } from "@/utils/store/central"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { Link } from "@tanstack/react-router"; -function TabPanel(props) { - const { children, value, index, ...other } = props; - - return ( - - ); -} - -TabPanel.propTypes = { - children: PropTypes.node, - index: PropTypes.number.isRequired, - value: PropTypes.number.isRequired, -}; - const getEpisodeDateString = (date: Date) => { const formatter = new Intl.DateTimeFormat(navigator.language ?? "en-US", { dateStyle: "full", @@ -109,6 +75,7 @@ function SeriesTitlePage() { const item = useQuery({ queryKey: ["item", id], queryFn: async () => { + if (!api) return null; const result = await getUserLibraryApi(api).getItem({ userId: user?.Id, itemId: id, @@ -123,48 +90,31 @@ function SeriesTitlePage() { const similarItems = useQuery({ queryKey: ["item", id, "similarItem"], queryFn: async () => { + if (!api) return null; const result = await getLibraryApi(api).getSimilarShows({ userId: user?.Id, - itemId: item.data.Id, + itemId: item.data?.Id ?? "", limit: 16, }); return result.data; }, enabled: item.isSuccess, - networkMode: "always", - refetchOnWindowFocus: true, }); const seasons = useQuery({ queryKey: ["item", id, "seasons"], queryFn: async () => { + if (!api) return null; + if (!item.data?.Id) return null; const result = await getTvShowsApi(api).getSeasons({ userId: user?.Id, seriesId: item.data.Id, - // isSpecialSeason: false, + isSpecialSeason: false, + isMissing: false, }); return result.data; }, enabled: item.isSuccess, - networkMode: "always", - refetchOnWindowFocus: true, - }); - - const nextUpEpisode = useQuery({ - queryKey: ["item", id, "nextUp"], - queryFn: async () => { - const result = await getTvShowsApi(api).getNextUp({ - userId: user?.Id, - limit: 1, - parentId: item.data.Id, - disableFirstEpisode: true, - fields: [ItemFields.Overview], - }); - return result.data; - }, - enabled: item.isSuccess && item.data.Type === "Series", - networkMode: "always", - refetchOnWindowFocus: true, }); const [backdropImage, setBackdropImage] = useState(() => { @@ -182,9 +132,10 @@ function SeriesTitlePage() { const currentSeasonItem = useQuery({ queryKey: ["item", id, "season", currentSeason], queryFn: async () => { + if (!api) return null; const result = await getUserLibraryApi(api).getItem({ userId: user?.Id, - itemId: seasons.data.Items[currentSeason].Id, + itemId: seasons.data?.Items?.[Number(currentSeason)].Id ?? "", }); return result.data; }, @@ -196,12 +147,13 @@ function SeriesTitlePage() { const episodes = useQuery({ queryKey: ["item", id, "season", currentSeason, "episodes"], queryFn: async () => { + if (!api) return null; const result = await getTvShowsApi(api).getEpisodes({ userId: user?.Id, - seriesId: item.data.Id, - seasonId: seasons.data.Items[currentSeason].Id, + seriesId: item.data?.Id ?? "", + seasonId: seasons.data?.Items?.[Number(currentSeason)].Id, fields: [ItemFields.Overview], - excludeLocationTypes: [LocationType.Virtual], + isMissing: false, }); return result.data; }, @@ -213,8 +165,9 @@ function SeriesTitlePage() { const specialFeatures = useQuery({ queryKey: ["item", id, "specialFeatures"], queryFn: async () => { + if (!api) return null; const result = await getUserLibraryApi(api).getSpecialFeatures({ - itemId: item.data.Id, + itemId: item.data?.Id ?? "", userId: user?.Id, }); return result.data; @@ -222,125 +175,102 @@ function SeriesTitlePage() { enabled: item.isSuccess, }); - const [directors, setDirectors] = useState([]); - const [writers, setWriters] = useState([]); - const [actors, setActors] = useState([]); - const [producers, setProducers] = useState([]); - - useLayoutEffect(() => { - if (item.isSuccess) { - // setBackdropImage({ - // url: getImageUrlsApi(api).getItemImageUrlById(item.data?.Id, "Backdrop", { - // tag: item.data?.BackdropImageTags[0], - // }), - // key: item.data?.BackdropImageTags[0], - // }); - // setBackdrop( - // getImageUrlsApi(api).getItemImageUrlById(item.data?.Id, "Backdrop", { - // tag: item.data?.BackdropImageTags[0], - // }), - // item.data.Id, - // ); - const direTp = item.data.People.filter((itm) => itm.Type === "Director"); - setDirectors(direTp); - const writeTp = item.data.People.filter((itm) => itm.Type === "Writer"); - setWriters(writeTp); - const producerTp = item.data.People.filter( - (itm) => itm.Type === "Producer", - ); - setProducers(producerTp); - const actorTp = item.data.People.filter((itm) => itm.Type === "Actor"); - setActors(actorTp); - } - }, [item.isSuccess]); - - useLayoutEffect(() => { - if ( - seasons.isSuccess && - !sessionStorage.getItem(`season-${item.data?.Id}`) - ) { - if ( - seasons.data.TotalRecordCount > 1 && - seasons.data.Items[0].Name.toLowerCase().includes("special") - ) { - setCurrentSeason(1); - } else { - setCurrentSeason(0); - } - } - }, [seasons.isSuccess]); + const directors = useMemo(() => { + return item.data?.People?.filter((itm) => itm.Type === "Director") ?? []; + }, [item.data?.Id]); + const writers = useMemo(() => { + return item.data?.People?.filter((itm) => itm.Type === "Writer") ?? []; + }, [item.data?.Id]); + const actors = useMemo(() => { + return item.data?.People?.filter((itm) => itm.Type === "Actor") ?? []; + }, [item.data?.Id]); + const producers = useMemo(() => { + return item.data?.People?.filter((itm) => itm.Type === "Producer") ?? []; + }, [item.data?.Id]); useEffect(() => { - if ( - currentSeasonItem.isSuccess && - currentSeasonItem.data?.BackdropImageTags?.length > 0 - ) { - sessionStorage.setItem( - `backdrop-${item.data?.Id}`, - getImageUrlsApi(api).getItemImageUrlById( - currentSeasonItem.data.Id, - "Backdrop", - { - tag: currentSeasonItem.data.BackdropImageTags?.[0], - }, - ), - ); - sessionStorage.setItem( - `backdrop-${item.data?.Id}-key`, - currentSeasonItem.data.BackdropImageTags?.[0], - ); - setBackdropImage({ - url: getImageUrlsApi(api).getItemImageUrlById( - currentSeasonItem.data.Id, - "Backdrop", - { - tag: currentSeasonItem.data.BackdropImageTags?.[0], - }, - ), - key: currentSeasonItem.data.BackdropImageTags?.[0], - }); - setBackdrop( - getImageUrlsApi(api).getItemImageUrlById( - currentSeasonItem.data.Id, - "Backdrop", - { - tag: currentSeasonItem.data.BackdropImageTags?.[0], - }, - ), - currentSeasonItem.data.BackdropImageTags?.[0], - ); - setBackdropImageLoaded(false); - } else if (item.isSuccess && item.data?.BackdropImageTags?.length > 0) { - sessionStorage.setItem( - `backdrop-${item.data?.Id}`, - getImageUrlsApi(api).getItemImageUrlById(item.data.Id, "Backdrop", { - tag: item.data.BackdropImageTags?.[0], - }), - ); - sessionStorage.setItem( - `backdrop-${item.data?.Id}-key`, - item.data?.BackdropImageTags?.[0], - ); - if (backdropImage.key !== item.data?.BackdropImageTags?.[0]) { - setBackdropImageLoaded(false); // Reset Backdrop image load status if previous image is diff then new image + if (api && currentSeasonItem.isSuccess && item.isSuccess) { + if ( + currentSeasonItem.isSuccess && + (currentSeasonItem.data?.BackdropImageTags?.length ?? 0) > 0 + ) { + sessionStorage.setItem( + `backdrop-${item.data?.Id}`, + getImageUrlsApi(api).getItemImageUrlById( + currentSeasonItem.data?.Id ?? "", + "Backdrop", + { + tag: currentSeasonItem.data?.BackdropImageTags?.[0], + }, + ), + ); + sessionStorage.setItem( + `backdrop-${item.data?.Id}-key`, + currentSeasonItem.data?.BackdropImageTags?.[0] ?? "", + ); + setBackdropImage({ + url: getImageUrlsApi(api).getItemImageUrlById( + currentSeasonItem.data?.Id ?? "", + "Backdrop", + { + tag: currentSeasonItem.data?.BackdropImageTags?.[0], + }, + ), + key: currentSeasonItem.data?.BackdropImageTags?.[0], + }); + setBackdrop( + getImageUrlsApi(api).getItemImageUrlById( + currentSeasonItem.data?.Id ?? "", + "Backdrop", + { + tag: currentSeasonItem.data?.BackdropImageTags?.[0], + }, + ), + currentSeasonItem.data?.BackdropImageTags?.[0], + ); + setBackdropImageLoaded(false); + } else if ( + item.isSuccess && + (item.data?.BackdropImageTags?.length ?? 0) > 0 + ) { + sessionStorage.setItem( + `backdrop-${item.data?.Id}`, + getImageUrlsApi(api).getItemImageUrlById( + item.data?.Id ?? "", + "Backdrop", + { + tag: item.data?.BackdropImageTags?.[0], + }, + ), + ); + sessionStorage.setItem( + `backdrop-${item.data?.Id}-key`, + item.data?.BackdropImageTags?.[0] ?? "", + ); + if (backdropImage.key !== item.data?.BackdropImageTags?.[0]) { + setBackdropImageLoaded(false); // Reset Backdrop image load status if previous image is diff then new image + } + setBackdropImage({ + url: getImageUrlsApi(api).getItemImageUrlById( + item.data?.Id ?? "", + "Backdrop", + { + tag: item.data?.BackdropImageTags?.[0], + }, + ), + key: item.data?.BackdropImageTags?.[0], + }); + setBackdrop( + getImageUrlsApi(api).getItemImageUrlById( + item.data?.Id ?? "", + "Backdrop", + { + tag: item.data?.BackdropImageTags?.[0], + }, + ), + item.data?.BackdropImageTags?.[0], + ); } - setBackdropImage({ - url: getImageUrlsApi(api).getItemImageUrlById( - item.data?.Id, - "Backdrop", - { - tag: item.data?.BackdropImageTags?.[0], - }, - ), - key: item.data?.BackdropImageTags?.[0], - }); - setBackdrop( - getImageUrlsApi(api).getItemImageUrlById(item.data.Id, "Backdrop", { - tag: item.data.BackdropImageTags?.[0], - }), - item.data.BackdropImageTags?.[0], - ); - // setBackdropImageLoaded(false); } }, [currentSeasonItem.dataUpdatedAt]); @@ -369,7 +299,7 @@ function SeriesTitlePage() { ); } - if (item.isSuccess && similarItems.isSuccess) { + if (item.isSuccess && item.data) { return ( ) : ( { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} style={{ y: parallax, @@ -436,53 +366,59 @@ function SeriesTitlePage() { aspectRatio: item.data.PrimaryImageAspectRatio ?? 1, }} > - {Object.keys(item.data.ImageTags).includes("Primary") ? ( - <> + {item.data.ImageTags?.Primary ? ( +
{item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-image" /> - +
) : (
- {getTypeIcon(item.data.Type)} + {getTypeIcon(item.data.Type ?? "Series")}
)}
- {Object.keys(item.data.ImageTags).includes("Logo") ? ( + {item.data.ImageTags?.Logo ? ( {item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-logo" /> @@ -587,7 +523,7 @@ function SeriesTitlePage() { {endsAt( item.data.RunTimeTicks - - item.data.UserData.PlaybackPositionTicks, + (item.data.UserData?.PlaybackPositionTicks ?? 0), )} )} @@ -605,10 +541,8 @@ function SeriesTitlePage() { }} >
- + {item.data.RemoteTrailers && ( + + )}
@@ -642,14 +578,11 @@ function SeriesTitlePage() {
- {item.data.Taglines?.length > 0 && ( + {(item.data.Taglines?.length ?? 0) > 0 && ( - {item.data.Taglines[0]} + {item.data.Taglines?.[0]} )} - - {item.data.Taglines[0] ?? ""} - - {item.data.ExternalUrls.map((url) => ( - - ))} + {item.data.ExternalUrls?.map( + (url) => + url.Url && + url.Name && ( + + ), + )}
- {actors.length > 0 && ( + {actors?.length > 0 && (
Actors @@ -682,23 +619,26 @@ function SeriesTitlePage() { {actor.PrimaryImageTag ? ( {actor.Name} ) : ( @@ -734,23 +674,26 @@ function SeriesTitlePage() { {actor.PrimaryImageTag ? ( {actor.Name} ) : ( @@ -786,23 +729,26 @@ function SeriesTitlePage() { {actor.PrimaryImageTag ? ( {actor.Name} ) : ( @@ -838,23 +784,26 @@ function SeriesTitlePage() { {actor.PrimaryImageTag ? ( {actor.Name} ) : ( @@ -904,7 +853,7 @@ function SeriesTitlePage() { }} > - {seasons.data.Items[currentSeason].Name} + {seasons.data?.Items?.[Number(currentSeason)].Name} ) : ( - episodes.data.TotalRecordCount + episodes.data?.TotalRecordCount ) } /> @@ -931,23 +880,21 @@ function SeriesTitlePage() { > {currentSeasonItem.isSuccess && ( )} {currentSeasonItem.isSuccess && ( - <> - - + )} - {seasons.data.Items.map((season, index) => { + {seasons.data?.Items?.map((season, index) => { return ( {season.Name} @@ -981,14 +928,14 @@ function SeriesTitlePage() { {episodes.isPending ? ( ) : ( - episodes.data.Items.map((episode, index) => { + episodes.data?.Items?.map((episode) => { return ( navigate({ to: "/episode/$id", - params: { id: episode.Id }, + params: { id: episode.Id ?? "" }, }) } initial={{ @@ -1033,6 +980,7 @@ function SeriesTitlePage() { currentSubTrack="nosub" size="medium" buttonProps={{ + //@ts-ignore color: "white", style: { color: "black ", @@ -1047,21 +995,24 @@ function SeriesTitlePage() {
{episode.Name} { - e.target.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} /> - {episode.UserData?.PlaybackPositionTicks > 0 && ( + {(episode.UserData?.PlaybackPositionTicks ?? 0) > 0 && (
)} - {getRuntimeCompact(episode.RunTimeTicks)} + {getRuntimeCompact(episode.RunTimeTicks ?? 0)}
)} - {specialFeatures.isSuccess && specialFeatures.data.length > 0 && ( - - {specialFeatures.data.map((special) => { - return ( - {}} - /> - ); - })} - - )} - {similarItems.data.TotalRecordCount > 0 && ( + {specialFeatures.isSuccess && + (specialFeatures.data?.length ?? 0) > 0 && ( + + {specialFeatures.data?.map((special) => { + return ( + {}} + /> + ); + })} + + )} + {(similarItems.data?.TotalRecordCount ?? 0) > 0 && ( - {similarItems.data.Items.map((similar) => { + {similarItems.data?.Items?.map((similar) => { return ( ); })}