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
+531 -218

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 { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
export const LatestMediaSection = ({ latestMediaLib }) => {
const user = useQuery({
@@ -67,7 +68,11 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
? "sqaure"
: "portait"
}
watchedStatus={item.UserData.Played}
watchedStatus={
item.Type == BaseItemKind.Audio
? false
: item.UserData.Played
}
watchedCount={
item.UserData.UnplayedItemCount
}
+394 -161
View File
@@ -32,7 +32,11 @@ import { showAppBar, showBackButton } from "../../utils/slice/appBar";
import { useDispatch, useSelector } from "react-redux";
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 { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
@@ -93,9 +97,6 @@ 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);
const appBarVisiblity = useSelector((state) => state.appBar.visible);
const [primageImageLoaded, setPrimaryImageLoaded] = useState(false);
const [backdropImageLoaded, setBackdropImageLoaded] = useState(false);
@@ -397,6 +398,45 @@ const ItemDetail = () => {
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) {
return (
<Box
@@ -434,6 +474,26 @@ const ItemDetail = () => {
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
recomponent="main"
@@ -447,7 +507,15 @@ const ItemDetail = () => {
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">
{item.data.Type != BaseItemKind.MusicAlbum
? item.data.BackdropImageTags.length !=
@@ -810,177 +878,342 @@ const ItemDetail = () => {
</Typography>
</Box>
</Box>
{item.data.Genres != 0 && (
<Box sx={{ mb: 2, width: "50%" }}>
<Stack
direction="row"
gap={1}
alignItems="center"
>
<Typography
className="item-detail-heading"
variant="h5"
mr={2}
>
Genre
</Typography>
{item.data.Genres.map(
(genre, index) => {
return (
<Chip
key={index}
variant="filled"
label={genre}
/>
);
},
)}
</Stack>
</Box>
)}
{item.data.Type == BaseItemKind.MusicAlbum && (
<Stack
sx={{ mb: 2 }}
direction="row"
gap={1}
alignItems="center"
>
<Typography
className="item-detail-heading"
variant="h5"
mr={2}
>
Artists
</Typography>
<Stack
direction="row"
gap={0.5}
divider={
<Typography variant="h6">
,
</Typography>
}
>
{item.data.Artists.map(
(mitem, mindex) => {
return (
<TableContainer>
<Table>
<TableBody>
{item.data.Genres != 0 && (
<TableRow
sx={{
"& td, & th": {
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
>
<Typography
key={mindex}
variant="h6"
className="item-detail-heading"
variant="h5"
mr={2}
>
{mitem}
Genre
</Typography>
);
},
</TableCell>
<TableCell>
<Stack
direction="row"
gap={1}
>
{item.data.Genres.map(
(
genre,
index,
) => {
return (
<Chip
key={
index
}
variant="filled"
label={
genre
}
/>
);
},
)}
</Stack>
</TableCell>
</TableRow>
)}
</Stack>
</Stack>
)}
{!!item.data.MediaStreams &&
item.data.MediaStreams.length != 0 && (
<>
<Box sx={{ mb: 2, width: "50%" }}>
<Stack
direction="row"
gap={1}
alignItems="center"
{item.data.Type ==
BaseItemKind.MusicAlbum && (
<TableRow
sx={{
"& td, & th": {
border: 0,
},
}}
>
<Typography
className="item-detail-heading"
variant="h5"
mr={2}
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
>
Video
</Typography>
<TextField
defaultValue={
item.data
.MediaStreams[0]
.DisplayTitle
}
select
fullWidth
hiddenLabel
>
{item.data.MediaStreams.map(
(
stream,
sindex,
) => {
if (
stream.Type ==
BaseItemKind.Video
)
<Typography
className="item-detail-heading"
variant="h5"
mr={2}
>
Artists
</Typography>
</TableCell>
<TableCell>
<Stack
direction="row"
gap={0.5}
divider={
<Typography variant="h6">
,
</Typography>
}
flexWrap="wrap"
>
{item.data.Artists.map(
(
mitem,
mindex,
) => {
return (
<MenuItem
<Typography
key={
sindex
}
value={
stream.DisplayTitle
mindex
}
variant="h6"
noWrap
>
{
stream.DisplayTitle
mitem
}
</MenuItem>
</Typography>
);
},
)}
</TextField>
</Stack>
</Box>
<Box sx={{ mb: 2, width: "50%" }}>
<Stack
direction="row"
gap={1}
alignItems="center"
>
<Typography
className="item-detail-heading"
variant="h5"
mr={2}
>
Audio
</Typography>
<TextField
select
fullWidth
hiddenLabel
>
{item.data.MediaStreams.map(
(
stream,
sindex,
) => {
if (
stream.Type ==
BaseItemKind.Audio
)
return (
<MenuItem
key={
sindex
}
value={
stream.DisplayTitle
}
>
{
stream.DisplayTitle
}
</MenuItem>
);
},
)}
</TextField>
</Stack>
</Box>
</>
)}
},
)}
</Stack>
</TableCell>
</TableRow>
)}
{!!item.data.MediaStreams &&
item.data.MediaStreams.length !=
0 && (
<>
{videoTracks != [] && (
<TableRow
sx={{
"& td, & th":
{
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
>
<Typography
className="item-detail-heading"
variant="h5"
mr={
2
}
>
Video
</Typography>
</TableCell>
<TableCell>
<TextField
select
sx={{
width: "50%",
}}
hiddenLabel
value={
currentVideoTrack
}
onChange={(
e,
) => {
setCurrentVideoTrack(
e
.target
.value,
);
}}
>
{videoTracks.map(
(
stream,
sindex,
) => {
if (
stream.Type ==
BaseItemKind.Video
)
return (
<MenuItem
key={
sindex
}
value={
stream.DisplayTitle
}
>
{
stream.DisplayTitle
}
</MenuItem>
);
},
)}
</TextField>
</TableCell>
</TableRow>
)}
{audioTracks != [] && (
<TableRow
sx={{
"& td, & th":
{
border: 0,
},
}}
>
<TableCell
sx={{
paddingLeft: 0,
width: "5%",
}}
>
<Typography
className="item-detail-heading"
variant="h5"
mr={
2
}
>
Audio
</Typography>
</TableCell>
<TableCell>
<TextField
select
sx={{
width: "50%",
}}
hiddenLabel
value={
currentAudioTrack
}
onChange={(
e,
) => {
setCurrentAudioTrack(
e
.target
.value,
);
}}
>
{audioTracks.map(
(
stream,
sindex,
) => {
return (
<MenuItem
key={
sindex
}
value={
stream.DisplayTitle
}
>
{
stream.DisplayTitle
}
</MenuItem>
);
},
)}
</TextField>
</TableCell>
</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 && (
<Box mt={3}>
<Typography variant="h5" mb={1}>
+130 -55
View File
@@ -58,6 +58,7 @@ import {
BaseItemKind,
CollectionTypeOptions,
ItemFields,
SortOrder,
} from "@jellyfin/sdk/lib/generated-client";
import { getRuntimeMusic } from "../../utils/date/time";
@@ -80,27 +81,21 @@ const LibraryView = () => {
const { id } = useParams();
const user = useQuery({
queryKey: ["libraryView", "user"],
queryKey: ["user"],
queryFn: async () => {
let usr = await getUserApi(window.api).getCurrentUser();
return usr.data;
},
networkMode: "always",
});
const [sortAscending, setSortAscending] = useState(true);
const [sortBy, setSortBy] = useState("SortName");
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 [sortBy, setSortBy] = useState();
const [sortByData, setSortByData] = useState();
const handleSortChange = (e) => {
setSortAscending(e.target.checked);
console.log(e.target.checked);
};
const handleSortBy = (e) => {
setSortBy(e.target.value);
@@ -118,6 +113,7 @@ const LibraryView = () => {
queryKey: ["libraryView", "currentLib", id],
queryFn: () => fetchLib(id),
enabled: !!user.data,
networkMode: "always",
});
if (currentLib.isSuccess) {
@@ -223,8 +219,8 @@ const LibraryView = () => {
]);
} else if (currentLib.data.Items[0].CollectionType == "music") {
setViewType([
{ title: "Songs", value: BaseItemKind.Audio },
{ title: "Albums", value: BaseItemKind.MusicAlbum },
{ title: "Songs", value: BaseItemKind.Audio },
{ title: "Artists", value: BaseItemKind.MusicArtist },
{ title: "Genres", value: BaseItemKind.MusicGenre },
]);
@@ -240,9 +236,63 @@ const LibraryView = () => {
} else {
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]);
useEffect(() => {
if (sortByData != undefined) {
setSortBy(sortByData[0].value);
}
}, [sortByData]);
const fetchLibItems = async (libraryId) => {
let result;
if (currentViewType == "MusicArtist") {
@@ -284,7 +334,11 @@ const LibraryView = () => {
? undefined
: true,
includeItemTypes: [currentViewType],
sortOrder: [sortAscending ? "Ascending" : "Descending"],
sortOrder: [
sortAscending
? SortOrder.Ascending
: SortOrder.Descending,
],
sortBy: sortBy,
filters: [
isPlayed && "IsPlayed",
@@ -318,7 +372,9 @@ const LibraryView = () => {
`page: ${page}`,
[
currentViewType,
sortAscending,
sortAscending ? SortOrder.Ascending : SortOrder.Descending,
,
sortBy,
[
isPlayed,
@@ -753,52 +809,68 @@ const LibraryView = () => {
currentViewType,
) && (
<>
<Checkbox
icon={<MdiSortDescending />}
checkedIcon={
<MdiSortAscending />
}
sx={{
color: "white !important",
}}
color="white"
onChange={handleSortChange}
defaultValue={sortAscending}
/>
<TextField
select
hiddenLabel
defaultValue={
sortByData[0].value
}
size="small"
variant="filled"
onChange={handleSortBy}
>
{sortByData.map(
(item, index) => {
return (
<MenuItem
key={
item.value
}
value={
item.value
}
>
{`By ${item.title}`}
</MenuItem>
);
},
)}
</TextField>
{sortByData != undefined && (
<>
<Checkbox
icon={
<MdiSortDescending />
}
checkedIcon={
<MdiSortAscending />
}
sx={{
color: "white !important",
}}
color="white"
onChange={
handleSortChange
}
checked={
sortAscending
}
/>
<TextField
select
hiddenLabel
value={
sortByData[0]
.value
}
size="small"
variant="filled"
onChange={
handleSortBy
}
>
{sortByData.map(
(
item,
index,
) => {
return (
<MenuItem
key={
index
}
value={
item.value
}
>
{`By ${item.title}`}
</MenuItem>
);
},
)}
</TextField>
</>
)}
</>
)}
{viewType.length != 0 && (
<TextField
select
hiddenLabel
defaultValue={viewType[0].value}
value={viewType[0].value}
size="small"
variant="filled"
onChange={handleCurrentViewType}
@@ -979,6 +1051,9 @@ const LibraryView = () => {
sx={{
opacity: 0.7,
}}
key={
aindex
}
>
{
artist
+1 -1
View File
@@ -76,7 +76,7 @@ export const getRuntimeFull = (ticks) => {
timeMin -= timeHr * 60;
formatedTime = `${timeHr} hour ${timeMin} minutes`;
} else {
formatedTime = `${timeMin} minutes ${timeSec} seconds`;
formatedTime = `${timeMin} minutes`;
}
return formatedTime;
};