Display tracks in item page #26

This commit is contained in:
prayag17 committed 2023-04-26 14:16:37 +05:30
1 parent 41c4c333d1
commit d3708bd83b
4 files changed
+394 -81

No files matched your search

@@ -7,6 +7,7 @@ import { CardsSkeleton } from "../skeleton/cards";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-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 { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
export const LatestMediaSection = ({ latestMediaLib }) => { export const LatestMediaSection = ({ latestMediaLib }) => {
const user = useQuery({ const user = useQuery({
@@ -67,7 +68,11 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
? "sqaure" ? "sqaure"
: "portait" : "portait"
} }
watchedStatus={item.UserData.Played} watchedStatus={
item.Type == BaseItemKind.Audio
? false
: item.UserData.Played
}
watchedCount={ watchedCount={
item.UserData.UnplayedItemCount item.UserData.UnplayedItemCount
} }
+288 -55
View File
@@ -32,7 +32,11 @@ import { showAppBar, showBackButton } from "../../utils/slice/appBar";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useParams, useNavigate } from "react-router-dom"; import { useParams, useNavigate } from "react-router-dom";
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client"; import {
BaseItemKind,
ItemFields,
MediaStreamType,
} from "@jellyfin/sdk/lib/generated-client";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-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 { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
@@ -93,9 +97,6 @@ const ItemDetail = () => {
const { id } = useParams(); const { id } = useParams();
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
const [isMovie, setIsMovie] = useState(false);
const [isSeries, setIsSeries] = useState(false);
const [isMusicItem, setIsMusicItem] = useState(false);
const appBarVisiblity = useSelector((state) => state.appBar.visible); const appBarVisiblity = useSelector((state) => state.appBar.visible);
const [primageImageLoaded, setPrimaryImageLoaded] = useState(false); const [primageImageLoaded, setPrimaryImageLoaded] = useState(false);
const [backdropImageLoaded, setBackdropImageLoaded] = useState(false); const [backdropImageLoaded, setBackdropImageLoaded] = useState(false);
@@ -397,6 +398,45 @@ const ItemDetail = () => {
personEpisodes.isLoading, personEpisodes.isLoading,
]); ]);
const [videoTracks, setVideoTracks] = useState([]);
const [audioTracks, setAudioTracks] = useState([]);
const [subtitleTracks, setSubtitleTracks] = useState([]);
const [currentVideoTrack, setCurrentVideoTrack] = useState();
const [currentAudioTrack, setCurrentAudioTrack] = useState();
const [currentSubTrack, setCurrentSubTrack] = useState();
useEffect(() => {
if (item.isSuccess && !!item.data.MediaStreams) {
let videos = [];
let audios = [];
let subs = [];
for (let track of item.data.MediaStreams) {
switch (track.Type) {
case MediaStreamType.Video:
videos.push(track);
break;
case MediaStreamType.Audio:
audios.push(track);
break;
case MediaStreamType.Subtitle:
subs.push(track);
break;
default:
break;
}
}
setVideoTracks(videos);
setAudioTracks(audios);
setSubtitleTracks(subs);
setCurrentVideoTrack(videos[0].DisplayTitle);
setCurrentAudioTrack(audios[0].DisplayTitle);
setCurrentSubTrack(subs[0].DisplayTitle);
}
}, [item.isSuccess]);
if (item.isLoading || similarItems.isLoading) { if (item.isLoading || similarItems.isLoading) {
return ( return (
<Box <Box
@@ -434,6 +474,26 @@ const ItemDetail = () => {
className="item-detail-image-blurhash" className="item-detail-image-blurhash"
/> />
)} )}
{!!item.data.ParentBackdropImageTags &&
item.data.ParentBackdropImageTags.length != 0 && (
<Blurhash
hash={
item.data.ImageBlurHashes.Backdrop[
item.data
.ParentBackdropImageTags[0]
]
}
width="100%"
height="100%"
resolutionX={14}
resolutionY={22}
style={{
aspectRatio: "0.666",
}}
punch={1}
className="item-detail-image-blurhash"
/>
)}
</Box> </Box>
<Box <Box
recomponent="main" recomponent="main"
@@ -447,7 +507,15 @@ const ItemDetail = () => {
flexFlow: "column", flexFlow: "column",
}} }}
> >
<Box className="item-detail-header" mb={0}> <Box
className="item-detail-header"
mb={0}
paddingTop={
item.data.Type == BaseItemKind.MusicAlbum
? 10
: 0
}
>
<Box className="item-detail-header-backdrop"> <Box className="item-detail-header-backdrop">
{item.data.Type != BaseItemKind.MusicAlbum {item.data.Type != BaseItemKind.MusicAlbum
? item.data.BackdropImageTags.length != ? item.data.BackdropImageTags.length !=
@@ -810,12 +878,22 @@ const ItemDetail = () => {
</Typography> </Typography>
</Box> </Box>
</Box> </Box>
<TableContainer>
<Table>
<TableBody>
{item.data.Genres != 0 && ( {item.data.Genres != 0 && (
<Box sx={{ mb: 2, width: "50%" }}> <TableRow
<Stack sx={{
direction="row" "& td, & th": {
gap={1} border: 0,
alignItems="center" },
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
> >
<Typography <Typography
className="item-detail-heading" className="item-detail-heading"
@@ -824,27 +902,49 @@ const ItemDetail = () => {
> >
Genre Genre
</Typography> </Typography>
</TableCell>
<TableCell>
<Stack
direction="row"
gap={1}
>
{item.data.Genres.map( {item.data.Genres.map(
(genre, index) => { (
genre,
index,
) => {
return ( return (
<Chip <Chip
key={index} key={
index
}
variant="filled" variant="filled"
label={genre} label={
genre
}
/> />
); );
}, },
)} )}
</Stack> </Stack>
</Box> </TableCell>
</TableRow>
)} )}
{item.data.Type == BaseItemKind.MusicAlbum && ( {item.data.Type ==
<Stack BaseItemKind.MusicAlbum && (
sx={{ mb: 2 }} <TableRow
direction="row" sx={{
gap={1} "& td, & th": {
alignItems="center" border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
> >
<Typography <Typography
className="item-detail-heading" className="item-detail-heading"
@@ -853,6 +953,8 @@ const ItemDetail = () => {
> >
Artists Artists
</Typography> </Typography>
</TableCell>
<TableCell>
<Stack <Stack
direction="row" direction="row"
gap={0.5} gap={0.5}
@@ -861,50 +963,83 @@ const ItemDetail = () => {
, ,
</Typography> </Typography>
} }
flexWrap="wrap"
> >
{item.data.Artists.map( {item.data.Artists.map(
(mitem, mindex) => { (
mitem,
mindex,
) => {
return ( return (
<Typography <Typography
key={mindex} key={
mindex
}
variant="h6" variant="h6"
noWrap
> >
{mitem} {
mitem
}
</Typography> </Typography>
); );
}, },
)} )}
</Stack> </Stack>
</Stack> </TableCell>
</TableRow>
)} )}
{!!item.data.MediaStreams && {!!item.data.MediaStreams &&
item.data.MediaStreams.length != 0 && ( item.data.MediaStreams.length !=
0 && (
<> <>
<Box sx={{ mb: 2, width: "50%" }}> {videoTracks != [] && (
<Stack <TableRow
direction="row" sx={{
gap={1} "& td, & th":
alignItems="center" {
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
> >
<Typography <Typography
className="item-detail-heading" className="item-detail-heading"
variant="h5" variant="h5"
mr={2} mr={
2
}
> >
Video Video
</Typography> </Typography>
</TableCell>
<TableCell>
<TextField <TextField
defaultValue={
item.data
.MediaStreams[0]
.DisplayTitle
}
select select
fullWidth sx={{
width: "50%",
}}
hiddenLabel hiddenLabel
value={
currentVideoTrack
}
onChange={(
e,
) => {
setCurrentVideoTrack(
e
.target
.value,
);
}}
> >
{item.data.MediaStreams.map( {videoTracks.map(
( (
stream, stream,
sindex, sindex,
@@ -930,35 +1065,59 @@ const ItemDetail = () => {
}, },
)} )}
</TextField> </TextField>
</Stack> </TableCell>
</Box> </TableRow>
<Box sx={{ mb: 2, width: "50%" }}> )}
<Stack {audioTracks != [] && (
direction="row" <TableRow
gap={1} sx={{
alignItems="center" "& td, & th":
{
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
> >
<Typography <Typography
className="item-detail-heading" className="item-detail-heading"
variant="h5" variant="h5"
mr={2} mr={
2
}
> >
Audio Audio
</Typography> </Typography>
</TableCell>
<TableCell>
<TextField <TextField
select select
fullWidth sx={{
width: "50%",
}}
hiddenLabel hiddenLabel
value={
currentAudioTrack
}
onChange={(
e,
) => {
setCurrentAudioTrack(
e
.target
.value,
);
}}
> >
{item.data.MediaStreams.map( {audioTracks.map(
( (
stream, stream,
sindex, sindex,
) => { ) => {
if (
stream.Type ==
BaseItemKind.Audio
)
return ( return (
<MenuItem <MenuItem
key={ key={
@@ -976,11 +1135,85 @@ const ItemDetail = () => {
}, },
)} )}
</TextField> </TextField>
</Stack> </TableCell>
</Box> </TableRow>
)}
{subtitleTracks !=
[] && (
<TableRow
sx={{
"& td, & th":
{
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
>
<Typography
className="item-detail-heading"
variant="h5"
mr={
2
}
>
Subtitle
</Typography>
</TableCell>
<TableCell>
<TextField
select
sx={{
width: "50%",
}}
hiddenLabel
value={
currentSubTrack
}
onChange={(
e,
) => {
setCurrentSubTrack(
e
.target
.value,
);
}}
>
{subtitleTracks.map(
(
stream,
sindex,
) => {
return (
<MenuItem
key={
sindex
}
value={
stream.DisplayTitle
}
>
{
stream.DisplayTitle
}
</MenuItem>
);
},
)}
</TextField>
</TableCell>
</TableRow>
)}
</> </>
)} )}
</TableBody>
</Table>
</TableContainer>
{!!item.data.Overview && ( {!!item.data.Overview && (
<Box mt={3}> <Box mt={3}>
<Typography variant="h5" mb={1}> <Typography variant="h5" mb={1}>
+99 -24
View File
@@ -58,6 +58,7 @@ import {
BaseItemKind, BaseItemKind,
CollectionTypeOptions, CollectionTypeOptions,
ItemFields, ItemFields,
SortOrder,
} from "@jellyfin/sdk/lib/generated-client"; } from "@jellyfin/sdk/lib/generated-client";
import { getRuntimeMusic } from "../../utils/date/time"; import { getRuntimeMusic } from "../../utils/date/time";
@@ -80,27 +81,21 @@ const LibraryView = () => {
const { id } = useParams(); const { id } = useParams();
const user = useQuery({ const user = useQuery({
queryKey: ["libraryView", "user"], queryKey: ["user"],
queryFn: async () => { queryFn: async () => {
let usr = await getUserApi(window.api).getCurrentUser(); let usr = await getUserApi(window.api).getCurrentUser();
return usr.data; return usr.data;
}, },
networkMode: "always",
}); });
const [sortAscending, setSortAscending] = useState(true); const [sortAscending, setSortAscending] = useState(true);
const [sortBy, setSortBy] = useState("SortName"); const [sortBy, setSortBy] = useState();
const [sortByData, setSortByData] = useState([ const [sortByData, setSortByData] = useState();
{ title: "Name", value: "SortName" },
{ title: "Critic Rating", value: "CriticRating" },
{ title: "Rating", value: "CommunityRating" },
{ title: "Release Date", value: "PremiereDate" },
{ title: "Date Added", value: "DateCreated" },
{ title: "Play Count", value: "PlayCount" },
{ title: "Runtime", value: "Runtime" },
{ title: "Random", value: "Random" },
]);
const handleSortChange = (e) => { const handleSortChange = (e) => {
setSortAscending(e.target.checked); setSortAscending(e.target.checked);
console.log(e.target.checked);
}; };
const handleSortBy = (e) => { const handleSortBy = (e) => {
setSortBy(e.target.value); setSortBy(e.target.value);
@@ -118,6 +113,7 @@ const LibraryView = () => {
queryKey: ["libraryView", "currentLib", id], queryKey: ["libraryView", "currentLib", id],
queryFn: () => fetchLib(id), queryFn: () => fetchLib(id),
enabled: !!user.data, enabled: !!user.data,
networkMode: "always",
}); });
if (currentLib.isSuccess) { if (currentLib.isSuccess) {
@@ -223,8 +219,8 @@ const LibraryView = () => {
]); ]);
} else if (currentLib.data.Items[0].CollectionType == "music") { } else if (currentLib.data.Items[0].CollectionType == "music") {
setViewType([ setViewType([
{ title: "Songs", value: BaseItemKind.Audio },
{ title: "Albums", value: BaseItemKind.MusicAlbum }, { title: "Albums", value: BaseItemKind.MusicAlbum },
{ title: "Songs", value: BaseItemKind.Audio },
{ title: "Artists", value: BaseItemKind.MusicArtist }, { title: "Artists", value: BaseItemKind.MusicArtist },
{ title: "Genres", value: BaseItemKind.MusicGenre }, { title: "Genres", value: BaseItemKind.MusicGenre },
]); ]);
@@ -240,9 +236,63 @@ const LibraryView = () => {
} else { } else {
setViewType([]); setViewType([]);
} }
if (currentLib.data.Items[0].CollectionType == "movies") {
setSortByData([
{ title: "Name", value: "SortName" },
{ title: "Critic Rating", value: "CriticRating" },
{ title: "Rating", value: "CommunityRating" },
{ title: "Date Added", value: "DateCreated" },
{ title: "Play Count", value: "PlayCount" },
{ title: "Release Date", value: "PremiereDate" },
{ title: "Runtime", value: "Runtime" },
{ title: "Random", value: "Random" },
]);
} else if (
currentLib.data.Items[0].CollectionType == "tvshows"
) {
setSortByData([
{ title: "Name", value: "SortName" },
{ title: "Critic Rating", value: "CriticRating" },
{ title: "Rating", value: "CommunityRating" },
{ title: "Date Added", value: "DateCreated" },
{ title: "Date Played", value: "DatePlayed" },
{ title: "Release Date", value: "PremiereDate" },
{ title: "Random", value: "Random" },
]);
} else if (currentLib.data.Items[0].CollectionType == "music") {
setSortByData([
{ title: "Name", value: "Name" },
{ title: "Album Artist", value: "AlbumArtist" },
{ title: "Critic Rating", value: "CriticRating" },
{ title: "Rating", value: "CommunityRating" },
{ title: "Release Date", value: "PremiereDate" },
{ title: "Date Added", value: "DateCreated" },
{ title: "Play Count", value: "PlayCount" },
{ title: "Runtime", value: "Runtime" },
{ title: "Random", value: "Random" },
]);
} else {
setSortByData([
{ title: "Name", value: "SortName" },
{ title: "Critic Rating", value: "CriticRating" },
{ title: "Rating", value: "CommunityRating" },
{ title: "Release Date", value: "PremiereDate" },
{ title: "Date Added", value: "DateCreated" },
{ title: "Play Count", value: "PlayCount" },
{ title: "Runtime", value: "Runtime" },
{ title: "Random", value: "Random" },
]);
}
} }
}, [currentLib.isSuccess]); }, [currentLib.isSuccess]);
useEffect(() => {
if (sortByData != undefined) {
setSortBy(sortByData[0].value);
}
}, [sortByData]);
const fetchLibItems = async (libraryId) => { const fetchLibItems = async (libraryId) => {
let result; let result;
if (currentViewType == "MusicArtist") { if (currentViewType == "MusicArtist") {
@@ -284,7 +334,11 @@ const LibraryView = () => {
? undefined ? undefined
: true, : true,
includeItemTypes: [currentViewType], includeItemTypes: [currentViewType],
sortOrder: [sortAscending ? "Ascending" : "Descending"], sortOrder: [
sortAscending
? SortOrder.Ascending
: SortOrder.Descending,
],
sortBy: sortBy, sortBy: sortBy,
filters: [ filters: [
isPlayed && "IsPlayed", isPlayed && "IsPlayed",
@@ -318,7 +372,9 @@ const LibraryView = () => {
`page: ${page}`, `page: ${page}`,
[ [
currentViewType, currentViewType,
sortAscending,
sortAscending ? SortOrder.Ascending : SortOrder.Descending,
,
sortBy, sortBy,
[ [
isPlayed, isPlayed,
@@ -752,9 +808,13 @@ const LibraryView = () => {
{!disabledSortViews.includes( {!disabledSortViews.includes(
currentViewType, currentViewType,
) && ( ) && (
<>
{sortByData != undefined && (
<> <>
<Checkbox <Checkbox
icon={<MdiSortDescending />} icon={
<MdiSortDescending />
}
checkedIcon={ checkedIcon={
<MdiSortAscending /> <MdiSortAscending />
} }
@@ -762,25 +822,35 @@ const LibraryView = () => {
color: "white !important", color: "white !important",
}} }}
color="white" color="white"
onChange={handleSortChange} onChange={
defaultValue={sortAscending} handleSortChange
}
checked={
sortAscending
}
/> />
<TextField <TextField
select select
hiddenLabel hiddenLabel
defaultValue={ value={
sortByData[0].value sortByData[0]
.value
} }
size="small" size="small"
variant="filled" variant="filled"
onChange={handleSortBy} onChange={
handleSortBy
}
> >
{sortByData.map( {sortByData.map(
(item, index) => { (
item,
index,
) => {
return ( return (
<MenuItem <MenuItem
key={ key={
item.value index
} }
value={ value={
item.value item.value
@@ -794,11 +864,13 @@ const LibraryView = () => {
</TextField> </TextField>
</> </>
)} )}
</>
)}
{viewType.length != 0 && ( {viewType.length != 0 && (
<TextField <TextField
select select
hiddenLabel hiddenLabel
defaultValue={viewType[0].value} value={viewType[0].value}
size="small" size="small"
variant="filled" variant="filled"
onChange={handleCurrentViewType} onChange={handleCurrentViewType}
@@ -979,6 +1051,9 @@ const LibraryView = () => {
sx={{ sx={{
opacity: 0.7, opacity: 0.7,
}} }}
key={
aindex
}
> >
{ {
artist artist
+1 -1
View File
@@ -76,7 +76,7 @@ export const getRuntimeFull = (ticks) => {
timeMin -= timeHr * 60; timeMin -= timeHr * 60;
formatedTime = `${timeHr} hour ${timeMin} minutes`; formatedTime = `${timeHr} hour ${timeMin} minutes`;
} else { } else {
formatedTime = `${timeMin} minutes ${timeSec} seconds`; formatedTime = `${timeMin} minutes`;
} }
return formatedTime; return formatedTime;
}; };