refactor: cleanup item.tsx
This commit is contained in:
1 file changed
+202
-215
+202
-215
@@ -1,11 +1,6 @@
|
|||||||
import PropTypes from "prop-types";
|
import React, { useState, useLayoutEffect, useRef, useMemo } from "react";
|
||||||
import React, { useState, useLayoutEffect, useRef } from "react";
|
|
||||||
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Chip from "@mui/material/Chip";
|
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 MenuItem from "@mui/material/MenuItem";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
@@ -19,14 +14,12 @@ import { motion, useScroll } from "framer-motion";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
ItemFields,
|
|
||||||
MediaStreamType,
|
MediaStreamType,
|
||||||
} from "@jellyfin/sdk/lib/generated-client";
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
|
||||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||||
|
|
||||||
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
import heroBg from "@/assets/herobg.png";
|
import heroBg from "@/assets/herobg.png";
|
||||||
import { Card } from "@/components/card/card";
|
import { Card } from "@/components/card/card";
|
||||||
@@ -67,34 +60,10 @@ import sdrIcon from "@/assets/icons/sdr.svg";
|
|||||||
import type MediaQualityInfo from "@/utils/types/mediaQualityInfo";
|
import type MediaQualityInfo from "@/utils/types/mediaQualityInfo";
|
||||||
|
|
||||||
import IconLink from "@/components/iconLink";
|
import IconLink from "@/components/iconLink";
|
||||||
import { queryClient } from "@/main";
|
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||||
|
|
||||||
function TabPanel(props) {
|
|
||||||
const { children, value, index, ...other } = props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
role="tabpanel"
|
|
||||||
hidden={value !== index}
|
|
||||||
id={`full-width-tabpanel-${index}`}
|
|
||||||
aria-labelledby={`full-width-tab-${index}`}
|
|
||||||
{...other}
|
|
||||||
style={{ marginTop: "1em" }}
|
|
||||||
>
|
|
||||||
{value === index && <Box>{children}</Box>}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TabPanel.propTypes = {
|
|
||||||
children: PropTypes.node,
|
|
||||||
index: PropTypes.number.isRequired,
|
|
||||||
value: PropTypes.number.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/_api/item/$id")({
|
export const Route = createFileRoute("/_api/item/$id")({
|
||||||
component: ItemDetail,
|
component: ItemDetail,
|
||||||
});
|
});
|
||||||
@@ -109,6 +78,7 @@ function ItemDetail() {
|
|||||||
const item = useQuery({
|
const item = useQuery({
|
||||||
queryKey: ["item", id],
|
queryKey: ["item", id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
if (!api) return null;
|
||||||
const result = await getUserLibraryApi(api).getItem({
|
const result = await getUserLibraryApi(api).getItem({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
itemId: id,
|
itemId: id,
|
||||||
@@ -120,207 +90,184 @@ function ItemDetail() {
|
|||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// const item = useSuspenseQuery({ queryKey: ["item", id] });
|
|
||||||
|
|
||||||
const similarItems = useQuery({
|
const similarItems = useQuery({
|
||||||
queryKey: ["item", id, "similarItem"],
|
queryKey: ["item", id, "similarItem"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
let result;
|
if (!api) return null;
|
||||||
if (item.data.Type === "Movie") {
|
if (!item.data?.Id) return null;
|
||||||
result = await getLibraryApi(api).getSimilarMovies({
|
if (item.data?.Type === "Movie") {
|
||||||
|
return (
|
||||||
|
await getLibraryApi(api).getSimilarMovies({
|
||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
itemId: item.data.Id,
|
itemId: item.data.Id,
|
||||||
limit: 16,
|
limit: 16,
|
||||||
});
|
})
|
||||||
} else if (item.data.Type === "Series") {
|
).data;
|
||||||
result = await getLibraryApi(api).getSimilarShows({
|
|
||||||
userId: user?.Id,
|
|
||||||
itemId: item.data.Id,
|
|
||||||
});
|
|
||||||
} else if (item.data.Type === "MusicAlbum") {
|
|
||||||
result = await getLibraryApi(api).getSimilarAlbums({
|
|
||||||
userId: user?.Id,
|
|
||||||
itemId: item.data.Id,
|
|
||||||
});
|
|
||||||
} else if (item.data.Type === "MusicArtist") {
|
|
||||||
result = await getLibraryApi(api).getSimilarArtists({
|
|
||||||
userId: user?.Id,
|
|
||||||
itemId: item.data.Id,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
result = await getLibraryApi(api).getSimilarItems({
|
|
||||||
userId: user?.Id,
|
|
||||||
itemId: item.data.Id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return result.data;
|
if (item.data?.Type === "Series") {
|
||||||
|
return (
|
||||||
|
await getLibraryApi(api).getSimilarShows({
|
||||||
|
userId: user?.Id,
|
||||||
|
itemId: item.data.Id,
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
}
|
||||||
|
if (item.data?.Type === "MusicAlbum") {
|
||||||
|
return (
|
||||||
|
await getLibraryApi(api).getSimilarAlbums({
|
||||||
|
userId: user?.Id,
|
||||||
|
itemId: item.data.Id,
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
}
|
||||||
|
if (item.data?.Type === "MusicArtist") {
|
||||||
|
return (
|
||||||
|
await getLibraryApi(api).getSimilarArtists({
|
||||||
|
userId: user?.Id,
|
||||||
|
itemId: item.data.Id,
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
await getLibraryApi(api).getSimilarItems({
|
||||||
|
userId: user?.Id,
|
||||||
|
itemId: item.data.Id,
|
||||||
|
})
|
||||||
|
).data;
|
||||||
},
|
},
|
||||||
enabled: item.isSuccess,
|
enabled: item.isSuccess,
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [videoTracks, setVideoTracks] = useState([]);
|
const [selectedVideoTrack, setSelectedVideoTrack] = useState(0);
|
||||||
const [audioTracks, setAudioTracks] = useState([]);
|
const [selectedAudioTrack, setSelectedAudioTrack] = useState(0);
|
||||||
const [subtitleTracks, setSubtitleTracks] = useState([]);
|
const [selectedSubtitleTrack, setSelectedSubtitleTrack] = useState(0);
|
||||||
|
|
||||||
const filterMediaStreamVideo = (source) => {
|
const videoTracks = useMemo(() => {
|
||||||
|
const result = item.data?.MediaStreams?.filter((source) => {
|
||||||
if (source.Type === MediaStreamType.Video) {
|
if (source.Type === MediaStreamType.Video) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
});
|
||||||
const filterMediaStreamAudio = (source) => {
|
setSelectedVideoTrack(result?.find((track) => track.IsDefault)?.Index ?? 0);
|
||||||
|
return result ?? [];
|
||||||
|
}, [item.data?.Id]);
|
||||||
|
const audioTracks = useMemo(() => {
|
||||||
|
const result = item.data?.MediaStreams?.filter((source) => {
|
||||||
if (source.Type === MediaStreamType.Audio) {
|
if (source.Type === MediaStreamType.Audio) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
});
|
||||||
const filterMediaStreamSubtitle = (source) => {
|
setSelectedAudioTrack(result?.find((track) => track.IsDefault)?.Index ?? 0);
|
||||||
|
return result ?? [];
|
||||||
|
}, [item.data?.Id]);
|
||||||
|
const subtitleTracks = useMemo(() => {
|
||||||
|
const result = item.data?.MediaStreams?.filter((source) => {
|
||||||
if (source.Type === MediaStreamType.Subtitle) {
|
if (source.Type === MediaStreamType.Subtitle) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
});
|
||||||
|
|
||||||
const [selectedVideoTrack, setSelectedVideoTrack] = useState(null);
|
|
||||||
const [selectedAudioTrack, setSelectedAudioTrack] = useState(null);
|
|
||||||
const [selectedSubtitleTrack, setSelectedSubtitleTrack] = useState(null);
|
|
||||||
|
|
||||||
const [directors, setDirectors] = useState([]);
|
|
||||||
const [writers, setWriters] = useState([]);
|
|
||||||
const [actors, setActors] = useState([]);
|
|
||||||
const [producers, setProducers] = useState([]);
|
|
||||||
|
|
||||||
const [mediaQualityInfo, setMediaQualityInfo] = useState<MediaQualityInfo>();
|
|
||||||
|
|
||||||
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
if (item.isSuccess) {
|
|
||||||
if (item.data.BackdropImageTags?.length > 0) {
|
|
||||||
setBackdrop(
|
|
||||||
getImageUrlsApi(api).getItemImageUrlById(item.data.Id, "Backdrop", {
|
|
||||||
tag: item.data.BackdropImageTags[0],
|
|
||||||
}),
|
|
||||||
item.data.BackdropImageTags[0],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setBackdrop("", "");
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (item.data.MediaStreams && item.data.MediaSources?.length > 0) {
|
|
||||||
const videos = item.data.MediaStreams.filter(filterMediaStreamVideo);
|
|
||||||
const audios = item.data.MediaStreams.filter(filterMediaStreamAudio);
|
|
||||||
const subs = item.data.MediaStreams.filter(filterMediaStreamSubtitle);
|
|
||||||
|
|
||||||
setSelectedVideoTrack(videos[0]?.Index ?? null);
|
|
||||||
setSelectedAudioTrack(
|
|
||||||
item.data.MediaSources[0].DefaultAudioStreamIndex ?? null,
|
|
||||||
);
|
|
||||||
setSelectedSubtitleTrack(
|
setSelectedSubtitleTrack(
|
||||||
item.data.MediaSources[0].DefaultSubtitleStreamIndex === -1 ||
|
result?.find((track) => track.IsDefault)?.Index ?? -1,
|
||||||
!item.data.MediaSources[0].DefaultSubtitleStreamIndex
|
|
||||||
? "nosub"
|
|
||||||
: item.data.MediaSources[0].DefaultSubtitleStreamIndex,
|
|
||||||
);
|
);
|
||||||
|
return result ?? [];
|
||||||
|
}, [item.data?.Id]);
|
||||||
|
|
||||||
setVideoTracks(videos);
|
const directors = useMemo(() => {
|
||||||
setAudioTracks(audios);
|
return item.data?.People?.filter((itm) => itm.Type === "Director") ?? [];
|
||||||
setSubtitleTracks(subs);
|
}, [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]);
|
||||||
|
|
||||||
// Analyze item for QualityInfo
|
const mediaQualityInfo = useMemo<MediaQualityInfo>(() => {
|
||||||
const checkAtmos = audios.filter((audio) =>
|
const checkAtmos = audioTracks.filter((audio) =>
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("atmos"),
|
audio.DisplayTitle?.toLocaleLowerCase().includes("atmos"),
|
||||||
);
|
);
|
||||||
const checkDolbyVision = videos.filter(
|
const checkDolbyVision = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("dv") ||
|
video.DisplayTitle?.toLocaleLowerCase().includes("dv") ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("dolby vision") ||
|
video.DisplayTitle?.toLocaleLowerCase().includes("dolby vision") ||
|
||||||
!!video.VideoDoViTitle ||
|
!!video.VideoDoViTitle ||
|
||||||
video.VideoRangeType === "DOVI",
|
video.VideoRangeType === "DOVI",
|
||||||
);
|
);
|
||||||
const checkDD = audios.filter(
|
const checkDD = audioTracks.filter(
|
||||||
(audio) =>
|
(audio) =>
|
||||||
(audio.DisplayTitle?.toLocaleLowerCase().includes("dd") &&
|
(audio.DisplayTitle?.toLocaleLowerCase().includes("dd") &&
|
||||||
!audio.DisplayTitle?.toLocaleLowerCase().includes("ddp")) ||
|
!audio.DisplayTitle?.toLocaleLowerCase().includes("ddp")) ||
|
||||||
(audio.DisplayTitle?.toLocaleLowerCase().includes(
|
(audio.DisplayTitle?.toLocaleLowerCase().includes("dolby digital") &&
|
||||||
"dolby digital",
|
!audio.DisplayTitle?.toLocaleLowerCase().includes("dolby digital+")),
|
||||||
) &&
|
|
||||||
!audio.DisplayTitle?.toLocaleLowerCase().includes(
|
|
||||||
"dolby digital+",
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
const checkDDP = audios.filter(
|
const checkDDP = audioTracks.filter(
|
||||||
(audio) =>
|
(audio) =>
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("ddp") ||
|
audio.DisplayTitle?.toLocaleLowerCase().includes("ddp") ||
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("dolby digital+"),
|
audio.DisplayTitle?.toLocaleLowerCase().includes("dolby digital+"),
|
||||||
);
|
);
|
||||||
const checkDts = audios.filter(
|
const checkDts = audioTracks.filter(
|
||||||
(audio) =>
|
(audio) =>
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("dts") &&
|
audio.DisplayTitle?.toLocaleLowerCase().includes("dts") &&
|
||||||
!audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd ma") &&
|
!audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd ma") &&
|
||||||
!audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd.ma"),
|
!audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd.ma"),
|
||||||
);
|
);
|
||||||
const checkDtsHDMA = audios.filter(
|
const checkDtsHDMA = audioTracks.filter(
|
||||||
(audio) =>
|
(audio) =>
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd ma") ||
|
audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd ma") ||
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd.ma"),
|
audio.DisplayTitle?.toLocaleLowerCase().includes("dts-hd.ma"),
|
||||||
);
|
);
|
||||||
const checkUHD = videos.filter(
|
const checkUHD = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("4k") ||
|
video.DisplayTitle?.toLocaleLowerCase().includes("4k") ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("2160p") ||
|
video.DisplayTitle?.toLocaleLowerCase().includes("2160p") ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("uhd"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("uhd"),
|
||||||
);
|
);
|
||||||
const checkHD = videos.filter(
|
const checkHD = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
(video.DisplayTitle?.toLocaleLowerCase().includes("hd") &&
|
(video.DisplayTitle?.toLocaleLowerCase().includes("hd") &&
|
||||||
!video.DisplayTitle?.toLocaleLowerCase().includes("hdr")) ||
|
!video.DisplayTitle?.toLocaleLowerCase().includes("hdr")) ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("1080p") ||
|
video.DisplayTitle?.toLocaleLowerCase().includes("1080p") ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("fhd"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("fhd"),
|
||||||
);
|
);
|
||||||
const checkSD = videos.filter(
|
const checkSD = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
(video.DisplayTitle?.toLocaleLowerCase().includes("sd") &&
|
(video.DisplayTitle?.toLocaleLowerCase().includes("sd") &&
|
||||||
!video.DisplayTitle?.toLocaleLowerCase().includes("sdr")) ||
|
!video.DisplayTitle?.toLocaleLowerCase().includes("sdr")) ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("720p"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("720p"),
|
||||||
);
|
);
|
||||||
const checkSDR = videos.filter(
|
const checkSDR = videoTracks.filter(
|
||||||
(video) => video.VideoRangeType === "SDR",
|
(video) => video.VideoRangeType === "SDR",
|
||||||
);
|
);
|
||||||
const checkHDR = videos.filter(
|
const checkHDR = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
video.VideoRange === "HDR" ||
|
video.VideoRange === "HDR" ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("dv"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("dv"),
|
||||||
);
|
);
|
||||||
const checkHDR10 = videos.filter(
|
const checkHDR10 = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
video.VideoRangeType === "HDR10" &&
|
video.VideoRangeType === "HDR10" &&
|
||||||
!video.DisplayTitle?.toLocaleLowerCase().includes("hdr10+"),
|
!video.DisplayTitle?.toLocaleLowerCase().includes("hdr10+"),
|
||||||
);
|
);
|
||||||
const checkHDR10Plus = videos.filter(
|
const checkHDR10Plus = videoTracks.filter(
|
||||||
(video) =>
|
(video) =>
|
||||||
video.VideoRangeType === "HDR10+" ||
|
video.VideoRangeType === "HDR10Plus" ||
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("hdr10+"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("hdr10+"),
|
||||||
);
|
);
|
||||||
const checkTrueHD = audios.filter((audio) =>
|
const checkTrueHD = audioTracks.filter((audio) =>
|
||||||
audio.DisplayTitle?.toLocaleLowerCase().includes("truehd"),
|
audio.DisplayTitle?.toLocaleLowerCase().includes("truehd"),
|
||||||
);
|
);
|
||||||
const checkIMAX = videos.filter((video) =>
|
const checkIMAX = videoTracks.filter((video) =>
|
||||||
video.DisplayTitle?.toLocaleLowerCase().includes("imax"),
|
video.DisplayTitle?.toLocaleLowerCase().includes("imax"),
|
||||||
);
|
);
|
||||||
setMediaQualityInfo({
|
return {
|
||||||
isAtmos: checkAtmos.length > 0,
|
isAtmos: checkAtmos.length > 0,
|
||||||
isDolbyVision: checkDolbyVision.length > 0,
|
isDolbyVision: checkDolbyVision.length > 0,
|
||||||
isDts: checkDts.length > 0,
|
isDts: checkDts.length > 0,
|
||||||
@@ -336,7 +283,26 @@ function ItemDetail() {
|
|||||||
isHDR10Plus: checkHDR10Plus.length > 0,
|
isHDR10Plus: checkHDR10Plus.length > 0,
|
||||||
isTrueHD: checkTrueHD.length > 0,
|
isTrueHD: checkTrueHD.length > 0,
|
||||||
isIMAX: checkIMAX.length > 0,
|
isIMAX: checkIMAX.length > 0,
|
||||||
});
|
};
|
||||||
|
}, [item.data?.Id]);
|
||||||
|
|
||||||
|
const setBackdrop = useBackdropStore((state) => state.setBackdrop);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (api && item.isSuccess && item.data) {
|
||||||
|
if ((item.data?.BackdropImageTags?.length ?? 0) > 0) {
|
||||||
|
setBackdrop(
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
item.data.Id ?? "",
|
||||||
|
"Backdrop",
|
||||||
|
{
|
||||||
|
tag: item.data.BackdropImageTags?.[0],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
item.data.BackdropImageTags?.[0],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setBackdrop("", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [item.isSuccess]);
|
}, [item.isSuccess]);
|
||||||
@@ -353,7 +319,7 @@ function ItemDetail() {
|
|||||||
return <ItemSkeleton />;
|
return <ItemSkeleton />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.isSuccess && similarItems.isSuccess) {
|
if (item.isSuccess && item.data) {
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
key={id}
|
key={id}
|
||||||
@@ -374,17 +340,20 @@ function ItemDetail() {
|
|||||||
<div className="item-hero-backdrop-container">
|
<div className="item-hero-backdrop-container">
|
||||||
{item.data.BackdropImageTags?.length ? (
|
{item.data.BackdropImageTags?.length ? (
|
||||||
<motion.img
|
<motion.img
|
||||||
alt={item.data.Name}
|
alt={item.data.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
item.data.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
item.data.Id ?? "",
|
||||||
"Backdrop",
|
"Backdrop",
|
||||||
{
|
{
|
||||||
tag: item.data.BackdropImageTags[0],
|
tag: item.data.BackdropImageTags[0],
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
className="item-hero-backdrop"
|
className="item-hero-backdrop"
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
y: parallax,
|
y: parallax,
|
||||||
@@ -392,11 +361,11 @@ function ItemDetail() {
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<motion.img
|
<motion.img
|
||||||
alt={item.data.Name}
|
alt={item.data.Name ?? ""}
|
||||||
src={heroBg}
|
src={heroBg}
|
||||||
className="item-hero-backdrop"
|
className="item-hero-backdrop"
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
y: parallax,
|
y: parallax,
|
||||||
@@ -410,44 +379,49 @@ function ItemDetail() {
|
|||||||
aspectRatio: item.data.PrimaryImageAspectRatio ?? 1,
|
aspectRatio: item.data.PrimaryImageAspectRatio ?? 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{Object.keys(item.data.ImageTags).includes("Primary") ? (
|
{item.data.ImageTags?.Primary ? (
|
||||||
<>
|
<div>
|
||||||
<Blurhash
|
<Blurhash
|
||||||
hash={
|
hash={
|
||||||
item.data.ImageBlurHashes.Primary[
|
item.data.ImageBlurHashes?.Primary?.[
|
||||||
item.data.ImageTags.Primary
|
item.data.ImageTags.Primary
|
||||||
]
|
] ?? ""
|
||||||
}
|
}
|
||||||
className="item-hero-image-blurhash"
|
className="item-hero-image-blurhash"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
alt={item.data.Name}
|
alt={item.data.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
item.data.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
item.data.Id ?? "",
|
||||||
"Primary",
|
"Primary",
|
||||||
{
|
{
|
||||||
quality: 90,
|
quality: 90,
|
||||||
tag: item.data.ImageTags.Primary,
|
tag: item.data.ImageTags.Primary,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
className="item-hero-image"
|
className="item-hero-image"
|
||||||
/>
|
/>
|
||||||
</>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="item-hero-image-icon">
|
<div className="item-hero-image-icon">
|
||||||
{getTypeIcon(item.data.Type)}
|
{getTypeIcon(item.data.Type ?? "Movie")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="item-hero-detail flex flex-column">
|
<div className="item-hero-detail flex flex-column">
|
||||||
{item.data.ImageTags?.Logo ? (
|
{item.data.ImageTags?.Logo ? (
|
||||||
<img
|
<img
|
||||||
alt={item.data.Name}
|
alt={item.data.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
item.data.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
item.data.Id ?? "",
|
||||||
"Logo",
|
"Logo",
|
||||||
{
|
{
|
||||||
quality: 90,
|
quality: 90,
|
||||||
@@ -455,9 +429,10 @@ function ItemDetail() {
|
|||||||
fillHeight: 592,
|
fillHeight: 592,
|
||||||
tag: item.data.ImageTags.Logo,
|
tag: item.data.ImageTags.Logo,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = 1;
|
e.currentTarget.style.opacity = "1";
|
||||||
}}
|
}}
|
||||||
className="item-hero-logo"
|
className="item-hero-logo"
|
||||||
/>
|
/>
|
||||||
@@ -595,7 +570,7 @@ function ItemDetail() {
|
|||||||
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
<Typography style={{ opacity: "0.8" }} variant="subtitle2">
|
||||||
{endsAt(
|
{endsAt(
|
||||||
item.data.RunTimeTicks -
|
item.data.RunTimeTicks -
|
||||||
item.data.UserData.PlaybackPositionTicks,
|
(item.data.UserData?.PlaybackPositionTicks ?? 0),
|
||||||
)}
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
@@ -694,9 +669,7 @@ function ItemDetail() {
|
|||||||
>
|
>
|
||||||
<PlayButton
|
<PlayButton
|
||||||
item={item.data}
|
item={item.data}
|
||||||
itemId={item.data.Id}
|
itemType={item.data.Type ?? "Movie"}
|
||||||
itemType={item.data.Type}
|
|
||||||
itemUserData={item.data.UserData}
|
|
||||||
currentVideoTrack={selectedVideoTrack}
|
currentVideoTrack={selectedVideoTrack}
|
||||||
currentAudioTrack={selectedAudioTrack}
|
currentAudioTrack={selectedAudioTrack}
|
||||||
currentSubTrack={selectedSubtitleTrack}
|
currentSubTrack={selectedSubtitleTrack}
|
||||||
@@ -707,22 +680,24 @@ function ItemDetail() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row" style={{ gap: "1em" }}>
|
<div className="flex flex-row" style={{ gap: "1em" }}>
|
||||||
|
{item.data.RemoteTrailers && (
|
||||||
<TrailerButton
|
<TrailerButton
|
||||||
trailerItem={item.data.RemoteTrailers}
|
trailerItem={item.data.RemoteTrailers}
|
||||||
disabled={item.data.RemoteTrailers?.length === 0}
|
disabled={item.data.RemoteTrailers?.length === 0}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<LikeButton
|
<LikeButton
|
||||||
itemName={item.data.Name}
|
itemName={item.data.Name}
|
||||||
itemId={item.data.Id}
|
itemId={item.data.Id}
|
||||||
queryKey={["item", id]}
|
queryKey={["item", id]}
|
||||||
isFavorite={item.data.UserData.IsFavorite}
|
isFavorite={item.data.UserData?.IsFavorite}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
<MarkPlayedButton
|
<MarkPlayedButton
|
||||||
itemName={item.data.Name}
|
itemName={item.data.Name}
|
||||||
itemId={item.data.Id}
|
itemId={item.data.Id}
|
||||||
queryKey={["item", id]}
|
queryKey={["item", id]}
|
||||||
isPlayed={item.data.UserData.Played}
|
isPlayed={item.data.UserData?.Played}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -730,9 +705,9 @@ function ItemDetail() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="item-detail">
|
<div className="item-detail">
|
||||||
<div style={{ width: "100%" }}>
|
<div style={{ width: "100%" }}>
|
||||||
{item.data.Taglines?.length > 0 && (
|
{(item.data.Taglines?.length ?? 0) > 0 && (
|
||||||
<Typography variant="h5" mb={2} fontWeight={300}>
|
<Typography variant="h5" mb={2} fontWeight={300}>
|
||||||
{item.data.Taglines[0]}
|
{item.data.Taglines?.[0]}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
<ShowMoreText
|
<ShowMoreText
|
||||||
@@ -755,7 +730,7 @@ function ItemDetail() {
|
|||||||
}}
|
}}
|
||||||
value={selectedVideoTrack}
|
value={selectedVideoTrack}
|
||||||
variant="filled"
|
variant="filled"
|
||||||
onChange={(e) => setSelectedVideoTrack(e.target.value)}
|
onChange={(e) => setSelectedVideoTrack(Number(e.target.value))}
|
||||||
>
|
>
|
||||||
{videoTracks.map((track) => (
|
{videoTracks.map((track) => (
|
||||||
<MenuItem key={track.Index} value={track.Index}>
|
<MenuItem key={track.Index} value={track.Index}>
|
||||||
@@ -774,7 +749,7 @@ function ItemDetail() {
|
|||||||
}}
|
}}
|
||||||
value={selectedAudioTrack}
|
value={selectedAudioTrack}
|
||||||
variant="filled"
|
variant="filled"
|
||||||
onChange={(e) => setSelectedAudioTrack(e.target.value)}
|
onChange={(e) => setSelectedAudioTrack(Number(e.target.value))}
|
||||||
>
|
>
|
||||||
{audioTracks.map((track) => (
|
{audioTracks.map((track) => (
|
||||||
<MenuItem key={track.Index} value={track.Index}>
|
<MenuItem key={track.Index} value={track.Index}>
|
||||||
@@ -797,9 +772,11 @@ function ItemDetail() {
|
|||||||
disablePortal: true,
|
disablePortal: true,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onChange={(e) => setSelectedSubtitleTrack(e.target.value)}
|
onChange={(e) =>
|
||||||
|
setSelectedSubtitleTrack(Number(e.target.value))
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<MenuItem key={-1} value={"nosub"}>
|
<MenuItem key={-1} value={-1}>
|
||||||
No Subtitle
|
No Subtitle
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{subtitleTracks.map((track) => (
|
{subtitleTracks.map((track) => (
|
||||||
@@ -817,13 +794,17 @@ function ItemDetail() {
|
|||||||
marginTop: "1em",
|
marginTop: "1em",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{item.data.ExternalUrls.map((url) => (
|
{item.data.ExternalUrls?.map(
|
||||||
<IconLink url={url.Url} name={url.Name} />
|
(url) =>
|
||||||
))}
|
url.Url &&
|
||||||
|
url.Name && (
|
||||||
|
<IconLink key={url.Name} url={url.Url} name={url.Name} />
|
||||||
|
),
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{item.data.People.length > 0 && (
|
{(item.data.People?.length ?? 0) > 0 && (
|
||||||
<div className="item-detail-cast">
|
<div className="item-detail-cast">
|
||||||
<Typography variant="h5" mb={2}>
|
<Typography variant="h5" mb={2}>
|
||||||
Cast & Crew
|
Cast & Crew
|
||||||
@@ -838,21 +819,24 @@ function ItemDetail() {
|
|||||||
key={actor.Id}
|
key={actor.Id}
|
||||||
to="/person/$id"
|
to="/person/$id"
|
||||||
params={{
|
params={{
|
||||||
id: actor.Id,
|
id: actor.Id ?? "",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{actor.PrimaryImageTag ? (
|
{actor.PrimaryImageTag ? (
|
||||||
<img
|
<img
|
||||||
alt={actor.Name}
|
alt={actor.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
actor.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
actor.Id ?? "",
|
||||||
"Primary",
|
"Primary",
|
||||||
{
|
{
|
||||||
quality: 80,
|
quality: 80,
|
||||||
fillWidth: 200,
|
fillWidth: 200,
|
||||||
fillHeight: 200,
|
fillHeight: 200,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
className="item-detail-cast-card-image"
|
className="item-detail-cast-card-image"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -890,16 +874,19 @@ function ItemDetail() {
|
|||||||
>
|
>
|
||||||
{actor.PrimaryImageTag ? (
|
{actor.PrimaryImageTag ? (
|
||||||
<img
|
<img
|
||||||
alt={actor.Name}
|
alt={actor.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
actor.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
actor.Id ?? "",
|
||||||
"Primary",
|
"Primary",
|
||||||
{
|
{
|
||||||
quality: 80,
|
quality: 80,
|
||||||
fillWidth: 200,
|
fillWidth: 200,
|
||||||
fillHeight: 200,
|
fillHeight: 200,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
className="item-detail-cast-card-image"
|
className="item-detail-cast-card-image"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -935,21 +922,24 @@ function ItemDetail() {
|
|||||||
to="/person/$id"
|
to="/person/$id"
|
||||||
key={actor.Id}
|
key={actor.Id}
|
||||||
params={{
|
params={{
|
||||||
id: actor.Id,
|
id: actor.Id ?? "",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{actor.PrimaryImageTag ? (
|
{actor.PrimaryImageTag ? (
|
||||||
<img
|
<img
|
||||||
alt={actor.Name}
|
alt={actor.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
actor.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
actor.Id ?? "",
|
||||||
"Primary",
|
"Primary",
|
||||||
{
|
{
|
||||||
quality: 80,
|
quality: 80,
|
||||||
fillWidth: 200,
|
fillWidth: 200,
|
||||||
fillHeight: 200,
|
fillHeight: 200,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
className="item-detail-cast-card-image"
|
className="item-detail-cast-card-image"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -983,23 +973,26 @@ function ItemDetail() {
|
|||||||
<Link
|
<Link
|
||||||
className="item-detail-cast-card"
|
className="item-detail-cast-card"
|
||||||
key={actor.Id}
|
key={actor.Id}
|
||||||
to={`/person/$id`}
|
to="/person/$id"
|
||||||
params={{
|
params={{
|
||||||
id: actor.Id,
|
id: actor.Id ?? "",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{actor.PrimaryImageTag ? (
|
{actor.PrimaryImageTag ? (
|
||||||
<img
|
<img
|
||||||
alt={actor.Name}
|
alt={actor.Name ?? ""}
|
||||||
src={getImageUrlsApi(api).getItemImageUrlById(
|
src={
|
||||||
actor.Id,
|
api &&
|
||||||
|
getImageUrlsApi(api).getItemImageUrlById(
|
||||||
|
actor.Id ?? "",
|
||||||
"Primary",
|
"Primary",
|
||||||
{
|
{
|
||||||
quality: 80,
|
quality: 80,
|
||||||
fillWidth: 200,
|
fillWidth: 200,
|
||||||
fillHeight: 200,
|
fillHeight: 200,
|
||||||
},
|
},
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
className="item-detail-cast-card-image"
|
className="item-detail-cast-card-image"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -1027,13 +1020,13 @@ function ItemDetail() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{similarItems.data.TotalRecordCount > 0 && (
|
{(similarItems.data?.TotalRecordCount ?? 0) > 0 && (
|
||||||
<CardScroller
|
<CardScroller
|
||||||
title="You might also like"
|
title="You might also like"
|
||||||
displayCards={7}
|
displayCards={7}
|
||||||
disableDecoration
|
disableDecoration
|
||||||
>
|
>
|
||||||
{similarItems.data.Items.map((similar) => {
|
{similarItems.data?.Items?.map((similar) => {
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={similar.Id}
|
key={similar.Id}
|
||||||
@@ -1066,12 +1059,6 @@ function ItemDetail() {
|
|||||||
}
|
}
|
||||||
queryKey={["item", id, "similarItem"]}
|
queryKey={["item", id, "similarItem"]}
|
||||||
userId={user?.Id}
|
userId={user?.Id}
|
||||||
imageBlurhash={
|
|
||||||
!!similar.ImageBlurHashes?.Primary &&
|
|
||||||
similar.ImageBlurHashes?.Primary[
|
|
||||||
Object.keys(similar.ImageBlurHashes.Primary)[0]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in new issue
Block a user