Update itemDetail page and fix few stuff #26

This commit is contained in:
prayag17 committed 2023-04-12 15:05:16 +05:30
1 parent 9ad438429f
commit d73eade38a
13 files changed
+875 -195

No files matched your search

+716 -159
View File
@@ -1,5 +1,6 @@
/** @format */
import { useState, useEffect } from "react";
import PropTypes from "prop-types";
import Box from "@mui/material/Box";
import CircularProgress from "@mui/material/CircularProgress";
@@ -10,16 +11,19 @@ import Divider from "@mui/material/Divider";
import LinearProgress from "@mui/material/LinearProgress";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Grid2 from "@mui/material/Unstable_Grid2";
import { Blurhash } from "react-blurhash";
import { showAppBar, showBackButton } from "../../utils/slice/appBar";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
import { useParams, useNavigate } from "react-router-dom";
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
import { useQuery } from "@tanstack/react-query";
import { MdiStarHalfFull } from "../../components/icons/mdiStarHalfFull";
@@ -31,9 +35,43 @@ import { CardScroller } from "../../components/cardScroller/cardScroller";
import "./item.module.scss";
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}
>
{value === index && (
<Box sx={{ p: 3 }}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.number.isRequired,
value: PropTypes.number.isRequired,
};
function a11yProps(index) {
return {
id: `full-width-tab-${index}`,
"aria-controls": `full-width-tabpanel-${index}`,
};
}
const ItemDetail = () => {
const { id } = useParams();
const dispatch = useDispatch();
const navigate = useNavigate();
const [isMovie, setIsMovie] = useState(false);
const [isSeries, setIsSeries] = useState(false);
const [isMusicItem, setIsMusicItem] = useState(false);
@@ -54,6 +92,7 @@ const ItemDetail = () => {
let usr = await getUserApi(window.api).getCurrentUser();
return usr.data;
},
networkMode: "always",
});
const item = useQuery({
@@ -66,6 +105,7 @@ const ItemDetail = () => {
return result.data;
},
enabled: !!user.data,
networkMode: "always",
});
const similarItems = useQuery({
@@ -101,6 +141,7 @@ const ItemDetail = () => {
return result.data;
},
enabled: item.isSuccess,
networkMode: "always",
});
const seasons = useQuery({
@@ -111,9 +152,113 @@ const ItemDetail = () => {
});
return result.data;
},
enabled: item.isSuccess,
enabled: item.isSuccess && item.data.Type == "Series",
networkMode: "always",
});
const [currentSeason, setCurrentSeason] = useState(0);
const episodes = useQuery({
queryKey: ["item", "episode", `season ${currentSeason + 1}`],
queryFn: async () => {
const result = await getTvShowsApi(window.api).getEpisodes({
seriesId: item.data.Id,
seasonId: seasons.data.Items[currentSeason].Id,
});
return result.data;
},
enabled: seasons.isSuccess,
networkMode: "always",
});
const personShows = useQuery({
queryKey: ["item", "personShows"],
queryFn: async () => {
const result = await getItemsApi(window.api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Series],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type == "Person",
networkMode: "always",
});
const personMovies = useQuery({
queryKey: ["item", "personMovies"],
queryFn: async () => {
const result = await getItemsApi(window.api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Movie],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type == "Person",
networkMode: "always",
});
const personBooks = useQuery({
queryKey: ["item", "personBooks"],
queryFn: async () => {
const result = await getItemsApi(window.api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Book],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
sortOrder: ["Descending"],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type == "Person",
networkMode: "always",
});
const personPhotos = useQuery({
queryKey: ["item", "personPhotos"],
queryFn: async () => {
const result = await getItemsApi(window.api).getItems({
userId: user.data.Id,
personIds: [id],
includeItemTypes: [BaseItemKind.Photo],
recursive: true,
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
});
return result.data;
},
enabled: item.isSuccess && item.data.Type == "Person",
networkMode: "always",
});
const personDataEmpty = (pitem) => {
let result;
switch (pitem) {
case "Movies":
result = personMovies.data.Items.length == 0;
break;
case "TV Shows":
result = personShows.data.Items.length == 0;
break;
case "Books":
result = personBooks.data.Items.length == 0;
break;
case "Photos":
result = personPhotos.data.Items.length == 0;
break;
default:
result = true;
break;
}
console.log("Result => ", result);
return result;
};
const [activePersonTab, setActivePersonTab] = useState(0);
const personTabs = ["Movies", "TV Shows", "Books", "Photos"];
if (item.isLoading || similarItems.isLoading) {
return (
<Box
@@ -128,8 +273,7 @@ const ItemDetail = () => {
<CircularProgress />
</Box>
);
}
if (item.isSuccess && similarItems.isSuccess) {
} else if (item.isSuccess && similarItems.isSuccess) {
return (
<>
<Box className="item-detail-backdrop">
@@ -147,6 +291,7 @@ const ItemDetail = () => {
style={{
aspectRatio: "0.666",
}}
punch={1}
className="item-detail-image-blurhash"
/>
)}
@@ -164,7 +309,7 @@ const ItemDetail = () => {
gap: 1,
}}
>
<Box className="item-detail-header" mb={5}>
<Box className="item-detail-header" mb={0}>
<Box className="item-detail-header-backdrop">
{item.data.BackdropImageTags.length != 0 && (
<img
@@ -211,150 +356,211 @@ const ItemDetail = () => {
{TypeIconCollectionCard[item.data.Type]}
</Box>
</Box>
<Box
className="item-detail-image-container"
sx={
item.data.Type.includes("Music") && {
aspectRatio: "1",
}
}
className="item-detail-info-container"
sx={{
display: "flex",
gap: 3,
flexDirection: "row",
alignItems: "flex-end",
justifyContent: "flex-start",
width: "100%",
}}
>
{!!item.data.ImageTags.Primary && (
<img
src={
window.api.basePath +
"/Items/" +
item.data.Id +
"/Images/Primary"
}
style={{
opacity: primageImageLoaded
? 1
: 0,
}}
className="item-detail-image"
onLoad={() =>
setPrimaryImageLoaded(true)
}
/>
)}
{!!item.data.ImageBlurHashes.Primary && (
<Blurhash
hash={
item.data.ImageBlurHashes
.Primary[
item.data.ImageTags
.Primary
<Box
className="item-detail-image-container"
sx={
item.data.Type.includes("Music")
? {
aspectRatio: "1",
}
: {}
}
>
{!!item.data.ImageTags.Primary && (
<img
src={
window.api.basePath +
"/Items/" +
item.data.Id +
"/Images/Primary?quality=10"
}
style={{
opacity: primageImageLoaded
? 1
: 0,
}}
className="item-detail-image"
onLoad={() =>
setPrimaryImageLoaded(
true,
)
}
/>
)}
{!!item.data.ImageBlurHashes
.Primary && (
<Blurhash
hash={
item.data.ImageBlurHashes
.Primary[
item.data.ImageTags
.Primary
]
}
width="100%"
height="100%"
resolutionX={64}
resolutionY={96}
style={{
aspectRatio: 0.666,
}}
className="item-detail-image-blurhash"
/>
)}
<div className="item-detail-image-icon-container">
{
TypeIconCollectionCard[
item.data.Type
]
}
width="100%"
height="100%"
resolutionX={64}
resolutionY={96}
style={{
aspectRatio: 0.666,
}}
className="item-detail-image-blurhash"
/>
)}
<div className="item-detail-image-icon-container">
{TypeIconCollectionCard[item.data.Type]}
</div>
</Box>
<Box className="item-detail-info-container">
<Box
className="item-detail-title-name"
sx={{ mb: 2 }}
>
<Typography variant="h3">
{item.data.Name}
</Typography>
{!!item.data.UserData
.PlayedPercentage && (
<LinearProgress
variant="determinate"
value={
item.data.UserData
.PlayedPercentage
}
sx={{
borderRadius: 1000,
width: "75%",
mt: 1,
mb: 1,
}}
color="primary"
/>
)}
<Typography
variant="subtitle1"
color="gray"
>
{item.data.OriginalTitle}
</Typography>
</div>
</Box>
<Stack
direction="row"
gap={2}
divider={
<Divider
variant="middle"
flexItem
orientation="vertical"
/>
}
ex={{ alignItems: "center" }}
<Box
sx={{
display: "flex",
flexDirection: "column",
}}
>
{item.data.ProductionYear && (
<Typography
sx={{ flexGrow: 0 }}
variant="subtitle1"
>
{item.data.ProductionYear}
</Typography>
)}
<Chip
variant="outlined"
label={
!!item.data.OfficialRating
? item.data
.OfficialRating
: "Not Rated"
}
/>
<Box
sx={{
display: "flex",
gap: "0.25em",
alignItems: "center",
}}
className="item-detail-info-rating"
className="item-detail-title-name"
sx={{ mb: 1 }}
>
{!!item.data.CommunityRating ? (
<>
<MdiStarHalfFull />
<Typography variant="subtitle1">
{Math.round(
item.data
.CommunityRating *
10,
) / 10}
</Typography>
</>
) : (
<Typography variant="subtitle1">
No Community Rating
</Typography>
)}
</Box>
{!!item.data.RunTimeTicks && (
<Typography variant="subtitle1">
{getRuntimeFull(
item.data.RunTimeTicks,
<Typography
variant="h3"
sx={{ width: "30%" }}
textOverflow="ellipsis"
whiteSpace="nowrap"
>
{!!item.data.ImageTags
.Logo ? (
<img
className="item-detail-title-logo"
src={`${window.api.basePath}/Items/${item.data.Id}/Images/Logo?quality=80&tag=${item.data.ImageTags.Logo}`}
/>
) : (
item.data.Name
)}
</Typography>
)}
</Stack>
{!!item.data.UserData
.PlayedPercentage && (
<LinearProgress
variant="determinate"
value={
item.data.UserData
.PlayedPercentage
}
sx={{
borderRadius: 1000,
width: "75%",
mt: 1,
mb: 1,
}}
color="primary"
/>
)}
<Typography
variant="subtitle1"
color="gray"
>
{item.data.OriginalTitle}
</Typography>
</Box>
<Stack
direction="row"
gap={2}
divider={
<Divider
variant="middle"
flexItem
orientation="vertical"
/>
}
sx={{
alignItems: "center",
width: "100%",
}}
>
{item.data.ProductionYear && (
<Typography
sx={{ flexGrow: 0 }}
variant="subtitle1"
>
{
item.data
.ProductionYear
}
</Typography>
)}
<Chip
variant="outlined"
label={
!!item.data
.OfficialRating
? item.data
.OfficialRating
: "Not Rated"
}
/>
<Box
sx={{
display: "flex",
gap: "0.25em",
alignItems: "center",
}}
className="item-detail-info-rating"
>
{!!item.data
.CommunityRating ? (
<>
<MdiStarHalfFull />
<Typography variant="subtitle1">
{Math.round(
item.data
.CommunityRating *
10,
) / 10}
</Typography>
</>
) : (
<Typography variant="subtitle1">
No Community Rating
</Typography>
)}
</Box>
{!!item.data.RunTimeTicks && (
<Typography variant="subtitle1">
{getRuntimeFull(
item.data
.RunTimeTicks,
)}
</Typography>
)}
</Stack>
</Box>
</Box>
<Box
className="item-detail-tagline"
sx={{ width: "100%" }}
>
<Typography
variant="h5"
fontStyle="italic"
sx={{ opacity: 0.8 }}
>
{item.data.Taglines[0]}
</Typography>
</Box>
</Box>
{item.data.Genres != 0 && (
@@ -381,9 +587,57 @@ const ItemDetail = () => {
</Stack>
</Box>
)}
<Typography variant="body1" mt={3} mb={5}>
{item.data.Overview}
</Typography>
{!!item.data.Overview && (
<Box mt={3}>
<Typography variant="h5" mb={1}>
Overview
</Typography>
<Typography
variant="body1"
sx={{ opacity: 0.8 }}
mb={5}
>
{item.data.Overview}
</Typography>
</Box>
)}
{seasons.isSuccess && (
<Box>
<Tabs
variant="scrollable"
scrollButtons="auto"
value={currentSeason}
onChange={(e, newVal) => {
setCurrentSeason(newVal);
}}
>
{seasons.data.Items.map(
(season, index) => {
return (
<Tab
label={season.Name}
{...a11yProps(
index,
)}
key={index}
/>
);
},
)}
</Tabs>
{seasons.data.Items.map((season, index) => {
return (
<TabPanel
value={currentSeason}
index={index}
key={index}
>
Item {index}
</TabPanel>
);
})}
</Box>
)}
{item.data.People.length != 0 && (
<CardScroller
headingProps={{
@@ -412,21 +666,320 @@ const ItemDetail = () => {
})}
</CardScroller>
)}
{seasons.isSuccess && (
<Box>
<Tabs value={0}>
{seasons.data.Items.map(
(season, index) => {
return (
<Tab
label={season.Name}
/>
);
},
)}
</Tabs>
</Box>
)}
{item.data.Type == "Person" &&
personShows.isSuccess &&
personMovies.isSuccess &&
personBooks.isSuccess &&
personPhotos.isSuccess && (
<Box>
<Box
sx={{
borderBottom: 1,
borderColor: "divider",
}}
>
<Tabs
value={activePersonTab}
onChange={(e, newVal) =>
setActivePersonTab(
newVal,
)
}
aria-label="person-tabs"
>
{personTabs.map(
(pitem, index) => {
return (
<Tab
label={
pitem
}
{...a11yProps(
index,
)}
disabled={
(pitem ==
"Movies" &&
personMovies
.data
.Items
.length ==
0) ||
(pitem ==
"TV Shows" &&
personShows
.data
.Items
.length ==
0) ||
(pitem ==
"Books" &&
personBooks
.data
.Items
.length ==
0) ||
(pitem ==
"Photos" &&
personPhotos
.data
.Items
.length ==
0)
? true
: false
}
key={
index
}
/>
);
},
)}
</Tabs>
</Box>
{personTabs.map((pitem, index) => {
return (
<TabPanel
value={activePersonTab}
index={index}
key={index}
>
{pitem == "Movies" && (
<Grid2
container
columns={{
xs: 2,
sm: 4,
md: 8,
}}
>
{personMovies.data.Items.map(
(
mitem,
mindex,
) => {
return (
<Grid2
key={
mindex
}
xs={
1
}
sm={
1
}
md={
1
}
>
<Card
itemName={
mitem.Name
}
itemId={
mitem.Id
}
imageTags={
!!mitem
.ImageTags
.Primary
}
subText={
mitem.ProductionYear
}
iconType={
mitem.Type
}
playedPercent={
!!mitem.UserData
? mitem
.UserData
.PlayedPercentage
: 0
}
cardOrientation={
mitem.Type ==
"MusicArtist" ||
mitem.Type ==
"MusicAlbum" ||
mitem.Type ==
"MusicGenre" ||
mitem.Type ==
"Playlist"
? "square"
: "portait"
}
watchedStatus={
!!mitem.UserData
? mitem
.UserData
.Played
: false
}
watchedCount={
!!mitem.UserData &&
mitem
.UserData
.UnplayedItemCount
}
blurhash={
mitem.ImageBlurHashes ==
{}
? ""
: !!mitem
.ImageTags
.Primary
? !!mitem
.ImageBlurHashes
.Primary
? mitem
.ImageBlurHashes
.Primary[
mitem
.ImageTags
.Primary
]
: ""
: ""
}
currentUser={
user.data
}
onClickEvent={() => {
navigate(
`/item/${mitem.Id}`,
);
}}
></Card>
</Grid2>
);
},
)}
</Grid2>
)}
{pitem == "TV Shows" && (
<Grid2
container
columns={{
xs: 4,
sm: 6,
md: 8,
}}
>
{personShows.data.Items.map(
(
mitem,
mindex,
) => {
return (
<Grid2
key={
mindex
}
xs={
1
}
sm={
1
}
md={
1
}
>
<Card
itemName={
mitem.Name
}
itemId={
mitem.Id
}
imageTags={
!!mitem
.ImageTags
.Primary
}
subText={
mitem.ProductionYear
}
iconType={
mitem.Type
}
playedPercent={
!!mitem.UserData
? mitem
.UserData
.PlayedPercentage
: 0
}
cardOrientation={
mitem.Type ==
"MusicArtist" ||
mitem.Type ==
"MusicAlbum" ||
mitem.Type ==
"MusicGenre" ||
mitem.Type ==
"Playlist"
? "square"
: "portait"
}
watchedStatus={
!!mitem.UserData
? mitem
.UserData
.Played
: false
}
watchedCount={
!!mitem.UserData &&
mitem
.UserData
.UnplayedItemCount
}
blurhash={
mitem.ImageBlurHashes ==
{}
? ""
: !!mitem
.ImageTags
.Primary
? !!mitem
.ImageBlurHashes
.Primary
? mitem
.ImageBlurHashes
.Primary[
mitem
.ImageTags
.Primary
]
: ""
: ""
}
currentUser={
user.data
}
onClickEvent={() => {
navigate(
`/item/${mitem.Id}`,
);
}}
></Card>
</Grid2>
);
},
)}
</Grid2>
)}
</TabPanel>
);
})}
</Box>
)}
{similarItems.data.Items.length != 0 && (
<CardScroller
headingProps={{
@@ -504,6 +1057,11 @@ const ItemDetail = () => {
simItem.UserData
.UnplayedItemCount
}
onClickEvent={() => {
navigate(
`/item/${simItem.Id}`,
);
}}
/>
);
},
@@ -513,8 +1071,7 @@ const ItemDetail = () => {
</Box>
</>
);
}
if (item.isError || similarItems.isError) {
} else if (item.isError || similarItems.isError) {
return <h1>{"Something went wrong :("}</h1>;
}
};