diff --git a/src/components/card/card.jsx b/src/components/card/card.jsx index 5208c78..13ceddb 100644 --- a/src/components/card/card.jsx +++ b/src/components/card/card.jsx @@ -177,7 +177,7 @@ export const Card = ({ currentVideoTrack={0} className="card-play-button" iconProps={{ - sx: { fontSize: "2.5em" }, + style: { fontSize: "2.5em" }, }} iconOnly /> @@ -203,7 +203,7 @@ export const Card = ({ {cardTitle} @@ -235,7 +235,7 @@ export const Card = ({ variant="subtitle2" noWrap textAlign="center" - sx={{ opacity: 0.6 }} + style={{ opacity: 0.6 }} lineHeight="auto" > {cardCaption} diff --git a/src/components/card/card.module.scss b/src/components/card/card.module.scss index 6648a2c..f89d48e 100644 --- a/src/components/card/card.module.scss +++ b/src/components/card/card.module.scss @@ -107,4 +107,9 @@ height: 15%; } } + &-episode { + .card-box { + height: unset !important; + } + } } diff --git a/src/components/card/episodeCard.jsx b/src/components/card/episodeCard.jsx index 61d3c5f..1dbb1c8 100644 --- a/src/components/card/episodeCard.jsx +++ b/src/components/card/episodeCard.jsx @@ -1,421 +1,218 @@ /** @format */ -import React, { useState } from "react"; -import PropTypes from "prop-types"; - import { useNavigate } from "react-router-dom"; -import Divider from "@mui/material/Divider"; -import Stack from "@mui/material/Stack"; -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 CardActionArea from "@mui/material/CardActionArea"; import Typography from "@mui/material/Typography"; import LinearProgress from "@mui/material/LinearProgress"; -import Chip from "@mui/material/Chip"; -import ButtonGroup from "@mui/material/ButtonGroup"; -import IconButton from "@mui/material/IconButton"; + import { Blurhash } from "react-blurhash"; -import { green, pink } from "@mui/material/colors"; -import { TypeIconCollectionCard } from "../utils/iconsCollection"; - -import { borderRadiusDefault } from "../../palette.module.scss"; import "./card.module.scss"; import { MdiCheck } from "../icons/mdiCheck"; -import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api"; -import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; -import { MdiHeartOutline } from "../icons/mdiHeartOutline"; -import { MdiHeart } from "../icons/mdiHeart"; -import { endsAt, getRuntime } from "../../utils/date/time"; -import { MdiStarHalfFull } from "../icons/mdiStarHalfFull"; +import LikeButton from "../buttons/likeButton"; +import MarkPlayedButton from "../buttons/markPlayedButton"; +import PlayButton from "../buttons/playButton"; +import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; +import { MdiTelevisionClassic } from "../icons/mdiTelevisionClassic"; +import { getRuntimeCompact } from "../../utils/date/time"; + +const availableSpecialRoutes = [BaseItemKind.Series]; + +/** + * @typedef {Object} Props + * @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item + * @property {string} cardTitle + * @property {string | number} cardCaption + * @property {string} imageBlurhash + * @property {Array} queryKey + * @property {string} userId + * @property {() => {}} onClick + */ + +/** + * @description Hero section for item pages + * @param {Props} + * @returns {React.Component} + */ export const EpisodeCard = ({ - itemName, - itemRating, - itemTicks, - itemId, - imageTags, - subText = "", - playedPercent, - cardProps, - onClickEvent, - watchedStatus, - blurhash, - currentUser, - favourite, - showName, - episodeLocation, - centerAlignText = false, - parentId, + item, + cardTitle, + cardCaption, + imageBlurhash, + queryKey, + userId, + onClick, }) => { const navigate = useNavigate(); - const [imgLoaded, setImgLoaded] = useState(false); - const [isWatched, setIsWatched] = useState(watchedStatus); - const [isFavourite, setIsFavourite] = useState(favourite); - const handleMarkAsPlayOrUnMarkAsPlay = async () => { - let result; - if (!isWatched) { - result = await getPlaystateApi(window.api).markPlayedItem({ - userId: currentUser.Id, - itemId: itemId, - }); - } else if (isWatched) { - result = await getPlaystateApi(window.api).markUnplayedItem({ - userId: currentUser.Id, - itemId: itemId, - }); + const defaultOnClick = () => { + if (availableSpecialRoutes.includes(item.Type)) { + navigate(`/${item.Type.toLocaleLowerCase()}/${item.Id}`); + } else { + navigate(`/item/${item.Id}`); } - setIsWatched(result.data.Played); }; - const handleLiking = async () => { - let result; - if (isFavourite) { - result = await getUserLibraryApi(window.api).unmarkFavoriteItem({ - userId: currentUser.Id, - itemId: itemId, - }); - } else if (!isFavourite) { - result = await getUserLibraryApi(window.api).markFavoriteItem({ - userId: currentUser.Id, - itemId: itemId, - }); - } - setIsFavourite(result.data.IsFavorite); - }; - return ( - - { - navigate(`/item/${itemId}`); - } - } - className="cardBox" - > - - <> - } - sx={{ - transition: "opacity 150ms", - opacity: isWatched ? 1 : 0, - }} - /> - - {imageTags && ( - setImgLoaded(true)} - className="card-image" - > - )} - - {!!blurhash && ( - +
+
+ {!!item.UserData && ( +
+ +
+ )} + {!!imageBlurhash && ( + )}
- {TypeIconCollectionCard["Episode"]} +
- {!!playedPercent && ( + (e.target.style.opacity = 1)} + className="card-image" + /> + +
+ + + +
+ {100 > item.UserData?.PlayedPercentage > 0 && ( )} - - +
- - { - e.stopPropagation(); - e.preventDefault(); - handleMarkAsPlayOrUnMarkAsPlay(); - }} - > - - - { - e.stopPropagation(); - e.preventDefault(); - handleLiking(); - }} - > - {isFavourite ? ( - - ) : ( - - )} - - - - - - - {!!showName && ( - <> - { - e.stopPropagation(); - navigate(`/item/${parentId}`); - }} - sx={{ - "&:hover": { - textDecoration: "underline", - }, - }} - > - {showName} - {" - "} - {episodeLocation} - - - )} - - - {itemName} + + {cardTitle} + + + {getRuntimeCompact(item.RunTimeTicks)} + +
+ + + {cardCaption} - {!!itemTicks && ( - - {getRuntime(itemTicks)} - - )} -
- - } - mb={1} - > - {!!itemRating && ( - - {" "} - {Math.round(itemRating * 10) / 10} - - )} - {!!itemTicks && ( - - {endsAt(itemTicks)} - - )} - - - {subText} - - - - +
+
+
+ ); }; - -EpisodeCard.propTypes = { - itemName: PropTypes.string.isRequired, - itemId: PropTypes.string.isRequired, - imageTags: PropTypes.bool, - subText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - playedPercent: PropTypes.number, - onClickEvent: PropTypes.func, - watchedStatus: PropTypes.bool, - blurhash: PropTypes.string, - currentUser: PropTypes.object, - favourite: PropTypes.bool, - showName: PropTypes.string, - episodeLocation: PropTypes.string, - itemTicks: PropTypes.number, - itemRating: PropTypes.number, - centerAlignText: PropTypes.bool, - parentId: PropTypes.any, -}; diff --git a/src/components/skeleton/episodeCards.jsx b/src/components/skeleton/episodeCards.jsx index f377cb5..1a7629e 100644 --- a/src/components/skeleton/episodeCards.jsx +++ b/src/components/skeleton/episodeCards.jsx @@ -53,13 +53,7 @@ export const EpisodeCardsSkeleton = () => { animation="wave" /> - - - + { variant="text" animation="wave" /> + , ChannelFolderItem: , CollectionFolder: , - Episode: , + Episode: , Folder: , LiveTvChannel: , LiveTvProgram: , diff --git a/src/routes/item/index.jsx b/src/routes/item/index.jsx index f608a9e..698e43f 100644 --- a/src/routes/item/index.jsx +++ b/src/routes/item/index.jsx @@ -601,90 +601,102 @@ const ItemDetail = () => { audioTracks={audioTracks} subtitleTracks={subtitleTracks} /> - - {item.data.People.map((person, index) => { - return ( - - ); - })} - - - {similarItems.data.Items.map((similar, index) => { - return ( - - ); - })} - + {item.data.People.length > 0 && ( + + {item.data.People.map((person, index) => { + return ( + + ); + })} + + )} + {similarItems.data.TotalRecordCount > 0 && ( + + {similarItems.data.Items.map((similar, index) => { + return ( + + ); + })} + + )} ); } diff --git a/src/routes/series/index.jsx b/src/routes/series/index.jsx index fd790b9..ad27630 100644 --- a/src/routes/series/index.jsx +++ b/src/routes/series/index.jsx @@ -392,15 +392,17 @@ const SeriesTitlePage = () => { } ) : ( episodes.data @@ -437,6 +439,70 @@ const SeriesTitlePage = () => { +
+ {episodes.isLoading ? ( + + ) : ( + episodes.data.Items.map( + (episode, index) => { + return ( + + + + ); + }, + ) + )} +
)} {specialFeatures.isSuccess && @@ -485,90 +551,102 @@ const SeriesTitlePage = () => { )} )} - - {item.data.People.map((person, index) => { - return ( - - ); - })} - - - {similarItems.data.Items.map((similar, index) => { - return ( - - ); - })} - + {item.data.People.length > 0 && ( + + {item.data.People.map((person, index) => { + return ( + + ); + })} + + )} + {similarItems.data.TotalRecordCount > 0 && ( + + {similarItems.data.Items.map((similar, index) => { + return ( + + ); + })} + + )} ); } diff --git a/src/routes/series/series.module.scss b/src/routes/series/series.module.scss index 8eec1f1..02a807c 100644 --- a/src/routes/series/series.module.scss +++ b/src/routes/series/series.module.scss @@ -10,4 +10,10 @@ width: 26%; flex-shrink: 0; } + &-episodes-container { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); + gap: 0.25em; + margin-top: 0.5em; + } } diff --git a/src/utils/date/time.js b/src/utils/date/time.js index a4a9770..921301c 100644 --- a/src/utils/date/time.js +++ b/src/utils/date/time.js @@ -98,6 +98,27 @@ export const getRuntimeFull = (ticks) => { return formatedTime; }; +/** + * @format + * @param {number} ticks - C# ticks of a particular item + * @return {number} Converted ticks to Hhr Mmin formate + */ +export const getRuntimeCompact = (ticks) => { + let time = ticksToMs(ticks); + let formatedTime = ""; + let timeSec = Math.floor(time / 1000); + let timeMin = Math.floor(timeSec / 60); + timeSec -= timeMin * 60; + if (timeMin > 60) { + let timeHr = Math.floor(timeMin / 60); + timeMin -= timeHr * 60; + formatedTime = `${timeHr}h ${timeMin}m`; + } else { + formatedTime = `${timeMin}m`; + } + return formatedTime; +}; + /** * @format * @param {number} ticks - C# ticks of a particular item