diff --git a/src/components/homeSection/latestMediaSection.jsx b/src/components/homeSection/latestMediaSection.jsx index c05c04f..debc51d 100644 --- a/src/components/homeSection/latestMediaSection.jsx +++ b/src/components/homeSection/latestMediaSection.jsx @@ -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 } diff --git a/src/routes/item/index.jsx b/src/routes/item/index.jsx index 1787414..f75c424 100644 --- a/src/routes/item/index.jsx +++ b/src/routes/item/index.jsx @@ -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 ( { className="item-detail-image-blurhash" /> )} + {!!item.data.ParentBackdropImageTags && + item.data.ParentBackdropImageTags.length != 0 && ( + + )} { flexFlow: "column", }} > - + {item.data.Type != BaseItemKind.MusicAlbum ? item.data.BackdropImageTags.length != @@ -810,177 +878,342 @@ const ItemDetail = () => { - {item.data.Genres != 0 && ( - - - - Genre - - {item.data.Genres.map( - (genre, index) => { - return ( - - ); - }, - )} - - - )} - - {item.data.Type == BaseItemKind.MusicAlbum && ( - - - Artists - - - , - - } - > - {item.data.Artists.map( - (mitem, mindex) => { - return ( + + + + {item.data.Genres != 0 && ( + + - {mitem} + Genre - ); - }, + + + + {item.data.Genres.map( + ( + genre, + index, + ) => { + return ( + + ); + }, + )} + + + )} - - - )} - {!!item.data.MediaStreams && - item.data.MediaStreams.length != 0 && ( - <> - - - - Video - - - {item.data.MediaStreams.map( - ( - stream, - sindex, - ) => { - if ( - stream.Type == - BaseItemKind.Video - ) + + Artists + + + + + , + + } + flexWrap="wrap" + > + {item.data.Artists.map( + ( + mitem, + mindex, + ) => { return ( - { - stream.DisplayTitle + mitem } - + ); - }, - )} - - - - - - - Audio - - - {item.data.MediaStreams.map( - ( - stream, - sindex, - ) => { - if ( - stream.Type == - BaseItemKind.Audio - ) - return ( - - { - stream.DisplayTitle - } - - ); - }, - )} - - - - - )} + }, + )} + + + + )} + {!!item.data.MediaStreams && + item.data.MediaStreams.length != + 0 && ( + <> + {videoTracks != [] && ( + + + + Video + + + + { + setCurrentVideoTrack( + e + .target + .value, + ); + }} + > + {videoTracks.map( + ( + stream, + sindex, + ) => { + if ( + stream.Type == + BaseItemKind.Video + ) + return ( + + { + stream.DisplayTitle + } + + ); + }, + )} + + + + )} + {audioTracks != [] && ( + + + + Audio + + + + { + setCurrentAudioTrack( + e + .target + .value, + ); + }} + > + {audioTracks.map( + ( + stream, + sindex, + ) => { + return ( + + { + stream.DisplayTitle + } + + ); + }, + )} + + + + )} + {subtitleTracks != + [] && ( + + + + Subtitle + + + + { + setCurrentSubTrack( + e + .target + .value, + ); + }} + > + {subtitleTracks.map( + ( + stream, + sindex, + ) => { + return ( + + { + stream.DisplayTitle + } + + ); + }, + )} + + + + )} + + )} + +
+
{!!item.data.Overview && ( diff --git a/src/routes/library/index.jsx b/src/routes/library/index.jsx index 2d71fd3..b970755 100644 --- a/src/routes/library/index.jsx +++ b/src/routes/library/index.jsx @@ -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, ) && ( <> - } - checkedIcon={ - - } - sx={{ - color: "white !important", - }} - color="white" - onChange={handleSortChange} - defaultValue={sortAscending} - /> - - {sortByData.map( - (item, index) => { - return ( - - {`By ${item.title}`} - - ); - }, - )} - + {sortByData != undefined && ( + <> + + } + checkedIcon={ + + } + sx={{ + color: "white !important", + }} + color="white" + onChange={ + handleSortChange + } + checked={ + sortAscending + } + /> + + {sortByData.map( + ( + item, + index, + ) => { + return ( + + {`By ${item.title}`} + + ); + }, + )} + + + )} )} {viewType.length != 0 && ( { sx={{ opacity: 0.7, }} + key={ + aindex + } > { artist diff --git a/src/utils/date/time.js b/src/utils/date/time.js index e297785..7bf3157 100644 --- a/src/utils/date/time.js +++ b/src/utils/date/time.js @@ -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; };