Add track selector and remaining time progress to itemHero #160

This commit is contained in:
Prayag Prajapati committed 2023-09-09 18:34:13 +05:30
1 parent f711440de3
commit 5c425b65c6
3 files changed
+207 -50

No files matched your search

+170 -32
View File
@@ -1,13 +1,17 @@
/** @format */ /** @format */
import { useEffect, useState } from "react";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import Chip from "@mui/material/Chip"; import Chip from "@mui/material/Chip";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import LinearProgress from "@mui/material/LinearProgress";
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
import { Card } from "../../card/card"; import { Card } from "../../card/card";
import { MdiStar } from "../../icons/mdiStar"; import { MdiStar } from "../../icons/mdiStar";
import { yellow } from "@mui/material/colors"; import { yellow } from "@mui/material/colors";
import { endsAt, getRuntime } from "../../../utils/date/time"; import { endsAt, getRuntime, getRuntimeFull } from "../../../utils/date/time";
import LikeButton from "../../buttons/likeButton"; import LikeButton from "../../buttons/likeButton";
import MarkPlayedButton from "../../buttons/markPlayedButton"; import MarkPlayedButton from "../../buttons/markPlayedButton";
import PlayButton from "../../buttons/playButton"; import PlayButton from "../../buttons/playButton";
@@ -23,7 +27,19 @@ const Hero = ({
writers = [], writers = [],
directors = [], directors = [],
artists = [], artists = [],
videoTracks = [],
audioTracks = [],
subtitleTracks = [],
}) => { }) => {
const [currentVideoIndex, setCurrentVideoIndex] = useState("");
const [currentAudioIndex, setCurrentAudioIndex] = useState("");
const [currentSubtitleIndex, setCurrentSubtitleIndex] = useState("");
useEffect(() => {
setCurrentVideoIndex(videoTracks[0]?.Index);
setCurrentAudioIndex(audioTracks[0]?.Index);
setCurrentSubtitleIndex(subtitleTracks[0]?.Index);
}, [videoTracks, audioTracks, subtitleTracks]);
return ( return (
<div <div
className="item-detail-hero" className="item-detail-hero"
@@ -204,6 +220,34 @@ const Hero = ({
{item.Genres.join(", ")} {item.Genres.join(", ")}
</Typography> </Typography>
</div> </div>
{item.UserData?.PlayedPercentage > 0 && (
<div
style={{
display: "flex",
alignItems: "center",
gap: "0.5em",
margin: " 1em 0 0 0",
}}
>
<LinearProgress
variant="determinate"
value={item.UserData?.PlayedPercentage}
style={{
width: "50%",
borderRadius: "1em",
}}
color="white"
/>
<Typography variant="subtitle1" fontWeight={600}>
{getRuntimeFull(
item.RunTimeTicks -
item.UserData
.PlaybackPositionTicks,
)}{" "}
remaining
</Typography>
</div>
)}
<div <div
style={{ style={{
margin: "1em 0", margin: "1em 0",
@@ -217,9 +261,9 @@ const Hero = ({
itemId={item.Id} itemId={item.Id}
userId={userId} userId={userId}
itemType={item.Type} itemType={item.Type}
currentAudioTrack={0} currentVideoTrack={currentVideoIndex}
currentSubTrack={0} currentAudioTrack={currentAudioIndex}
currentVideoTrack={0} currentSubTrack={currentSubtitleIndex}
buttonProps={{ buttonProps={{
size: "large", size: "large",
}} }}
@@ -240,6 +284,122 @@ const Hero = ({
userId={userId} userId={userId}
/> />
</div> </div>
<div
style={{
display: "flex",
flexDirection: "column",
gap: "0.4em",
maxWidth: "60%",
}}
>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Video
</Typography>
<TextField
size="small"
value={currentVideoIndex}
select
onChange={(e) =>
setCurrentVideoIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{videoTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Audio
</Typography>
<TextField
size="small"
value={currentAudioIndex}
select
onChange={(e) =>
setCurrentAudioIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{audioTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Subtitle
</Typography>
<TextField
size="small"
value={currentSubtitleIndex}
select
onChange={(e) =>
setCurrentSubtitleIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{subtitleTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
</div>
<div <div
style={{ style={{
marginTop: "0.2em", marginTop: "0.2em",
@@ -260,27 +420,17 @@ const Hero = ({
}} }}
> >
{writers.length > 0 && ( {writers.length > 0 && (
<div <div className="hero-grid">
style={{
display: "flex",
}}
>
<Typography <Typography
variant="subtitle1" variant="subtitle1"
style={{ style={{
opacity: 0.6, opacity: 0.6,
width: "15%",
}} }}
noWrap noWrap
> >
Written by Written by
</Typography> </Typography>
<Typography <Typography variant="subtitle1">
variant="subtitle1"
style={{
width: "85%",
}}
>
{writers {writers
.map((writer) => writer.Name) .map((writer) => writer.Name)
.join(", ")} .join(", ")}
@@ -290,26 +440,20 @@ const Hero = ({
{directors.length > 0 && ( {directors.length > 0 && (
<div <div
style={{ style={{
display: "flex",
marginTop: "0.5em", marginTop: "0.5em",
}} }}
className="hero-grid"
> >
<Typography <Typography
variant="subtitle1" variant="subtitle1"
style={{ style={{
opacity: 0.6, opacity: 0.6,
width: "15%",
}} }}
noWrap noWrap
> >
Directed by Directed by
</Typography> </Typography>
<Typography <Typography variant="subtitle1">
variant="subtitle1"
style={{
width: "85%",
}}
>
{directors {directors
.map((director) => director.Name) .map((director) => director.Name)
.join(", ")} .join(", ")}
@@ -320,25 +464,19 @@ const Hero = ({
<div <div
style={{ style={{
display: "flex", display: "flex",
marginTop: "0.5em",
}} }}
className="hero-grid"
> >
<Typography <Typography
variant="subtitle1" variant="subtitle1"
style={{ style={{
opacity: 0.6, opacity: 0.6,
width: "15%",
}} }}
noWrap noWrap
> >
Artists Artists
</Typography> </Typography>
<Typography <Typography variant="subtitle1">
variant="subtitle1"
style={{
width: "85%",
}}
>
{artists {artists
.map((director) => director.Name) .map((director) => director.Name)
.join(", ")} .join(", ")}
@@ -47,4 +47,9 @@ $maskPercentage: 40%;
} }
} }
} }
&-grid {
display: grid;
width: 100%;
grid-template-columns: 1fr 85%;
}
} }
+32 -18
View File
@@ -486,26 +486,37 @@ const ItemDetail = () => {
const [currentAudioTrack, setCurrentAudioTrack] = useState(""); const [currentAudioTrack, setCurrentAudioTrack] = useState("");
const [currentSubTrack, setCurrentSubTrack] = useState(""); const [currentSubTrack, setCurrentSubTrack] = useState("");
const filterMediaStreamVideo = (source) => {
if (source.Type == MediaStreamType.Video) {
return true;
}
return false;
};
const filterMediaStreamAudio = (source) => {
if (source.Type == MediaStreamType.Audio) {
return true;
}
return false;
};
const filterMediaStreamSubtitle = (source) => {
if (source.Type == MediaStreamType.Subtitle) {
return true;
}
return false;
};
useEffect(() => { useEffect(() => {
if (item.isSuccess && !!item.data.MediaStreams) { if (item.isSuccess && !!item.data.MediaStreams) {
let videos = []; let videos = item.data.MediaStreams.filter(
let audios = []; filterMediaStreamVideo,
let subs = []; );
for (let track of item.data.MediaStreams) { console.log(videos);
switch (track.Type) { let audios = item.data.MediaStreams.filter(
case MediaStreamType.Video: filterMediaStreamAudio,
videos.push(track); );
break; let subs = item.data.MediaStreams.filter(
case MediaStreamType.Audio: filterMediaStreamSubtitle,
audios.push(track); );
break;
case MediaStreamType.Subtitle:
subs.push(track);
break;
default:
break;
}
}
setVideoTracks(videos); setVideoTracks(videos);
setAudioTracks(audios); setAudioTracks(audios);
@@ -591,6 +602,9 @@ const ItemDetail = () => {
queryKey={["item", id]} queryKey={["item", id]}
writers={writers} writers={writers}
directors={directors} directors={directors}
videoTracks={videoTracks}
audioTracks={audioTracks}
subtitleTracks={subtitleTracks}
/> />
<CardScroller <CardScroller
title="Cast & Crew" title="Cast & Crew"