diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index a74a95b..1fd89d5 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -147,12 +147,18 @@ const PlayButton = ({ // startItemId: item.Id, }); - if (result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) === -1) { + if ( + result.data.Items?.map((i) => i.Id).indexOf( + currentEpisodeId, + ) === -1 + ) { throw new Error( `Episode having id ${currentEpisodeId} not found, index return -1`, ); } - index = result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) ?? 0; + index = + result.data.Items?.map((i) => i.Id).indexOf(currentEpisodeId) ?? + 0; if (currentAudioTrack === "auto") { const defaultAudioStreamIndex = result.data.Items?.[index].MediaSources?.[0] @@ -275,11 +281,6 @@ const PlayButton = ({ } break; case BaseItemKind.Playlist: - result = await getPlaylistsApi(api).getPlaylistItems({ - userId: userId, - playlistId: playlistItemId, - }); - break; case BaseItemKind.MusicAlbum: result = await getItemsApi(api).getItems({ parentId: item.Id, @@ -351,7 +352,6 @@ const PlayButton = ({ }, }); } - } break; case BaseItemKind.Photo: @@ -451,10 +451,7 @@ const PlayButton = ({ return; } - if (trackIndex) { - // Playlist Playback - enqueueSnackbar("Playlist playback is WIP", { variant: "info" }); - } else if (audio) { + if (audio) { // Album/Individual audio track playback const playbackUrl = generateAudioStreamUrl( result?.item?.Items?.[0].Id, @@ -500,7 +497,7 @@ const PlayButton = ({ currentSubTrack, result?.mediaSource?.MediaSources?.[0]?.MediaStreams, ); - + // Audio const audio = { track: diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 2d40e7c..defa351 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -715,7 +715,7 @@ export const routeTree = rootRoute "parent": "/_api" }, "/_api/playlist/$id": { - "filePath": "_api/playlist/$id.jsx", + "filePath": "_api/playlist/$id.tsx", "parent": "/_api" }, "/_api/series/$id": { diff --git a/src/routes/_api/library/$id.tsx b/src/routes/_api/library/$id.tsx index fd2c15c..220803c 100644 --- a/src/routes/_api/library/$id.tsx +++ b/src/routes/_api/library/$id.tsx @@ -53,7 +53,7 @@ import { useApiInContext } from "@/utils/store/api"; import { useCentralStore } from "@/utils/store/central"; import { createFileRoute } from "@tanstack/react-router"; -type SortByObject = { title: string; value: ItemSortBy }; +type SortByObject = { title: string; value: string }; type ViewObject = { title: string; value: BaseItemKind | "Artist" }; // type allowedFilters = ["movies", "tvshows", "music", "books"]; @@ -215,6 +215,9 @@ function Library() { }, ]; break; + case CollectionType.Playlists: + result = [{ title: "Playlist", value: BaseItemKind.Playlist }]; + break; default: result = []; } @@ -243,7 +246,7 @@ function Library() { Dvd: undefined, }); - const [sortBy, setSortBy] = useState("Name"); + const [sortBy, setSortBy] = useState("Name"); const [sortAscending, setSortAscending] = useState( () => JSON.parse( @@ -344,6 +347,47 @@ function Library() { }, ]; break; + case BaseItemKind.Playlist: + result = [ + { + title: "Name", + value: ItemSortBy.SortName, + }, + { + title: "Community Rating", + value: ItemSortBy.CommunityRating, + }, + { + title: "Critics Rating", + value: ItemSortBy.CriticRating, + }, + { + title: "Date Added", + value: ItemSortBy.DateCreated, + }, + { + title: "Date Played", + value: ItemSortBy.DatePlayed, + }, + { + title: "Folder", + value: `${ItemSortBy.IsFolder},${ItemSortBy.SortName}`, + }, + { title: "Parenal Rating", value: ItemSortBy.OfficialRating }, + { + title: "Play Count", + value: ItemSortBy.PlayCount, + }, + { + title: "Release Date", + value: `${ItemSortBy.ProductionYear},${ItemSortBy.PremiereDate},${ItemSortBy.SortName}`, + }, + { + title: "Random", + value: ItemSortBy.Random, + }, + ]; + break; default: result = []; break; @@ -587,7 +631,7 @@ function Library() { sortOrder: [ sortAscending ? SortOrder.Ascending : SortOrder.Descending, ], - sortBy: [sortBy], + sortBy: sortBy.split(",") as ItemSortBy[], filters: filtersArray, hasSubtitles: filters.hasSubtitles ? true : undefined, hasTrailer: filters.hasTrailer ? true : undefined, @@ -623,7 +667,7 @@ function Library() { sortOrder: [ sortAscending ? SortOrder.Ascending : SortOrder.Descending, ], - sortBy: [sortBy], + sortBy: sortBy.split(",") as ItemSortBy[], filters: filtersArray, hasSubtitles: filters.hasSubtitles ? true : undefined, hasTrailer: filters.hasTrailer ? true : undefined, @@ -844,7 +888,7 @@ function Library() { gap={1.2} className="library-items-options" > - {!disableSort && ( + {!disableSort && sortBy && (
{ @@ -874,7 +918,7 @@ function Library() { value={sortBy ?? "Name"} size="small" onChange={(e) => { - setSortBy(e.target.value as ItemSortBy); + setSortBy(e.target.value); console.info(e); sessionStorage.setItem( `library-${currentLib.data?.Id}-config_sort`, @@ -886,7 +930,7 @@ function Library() { }} > {sortByOptions.map((item) => ( - + {item.title} ))} diff --git a/src/routes/_api/playlist/$id.jsx b/src/routes/_api/playlist/$id.jsx deleted file mode 100644 index 749ba2e..0000000 --- a/src/routes/_api/playlist/$id.jsx +++ /dev/null @@ -1,223 +0,0 @@ -import PropTypes from "prop-types"; -import React, { useEffect } from "react"; - -import Box from "@mui/material/Box"; -import CircularProgress from "@mui/material/CircularProgress"; - -import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client"; -import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; -import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api/playlists-api"; -import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; -import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; - -import { useQuery } from "@tanstack/react-query"; - -import { Card } from "@/components/card/card"; -import CardScroller from "@/components/cardScroller/cardScroller"; - -import MusicTrack from "@/components/musicTrack"; -import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; -import { useBackdropStore } from "@/utils/store/backdrop"; -import "./playlist.scss"; -import { useCentralStore } from "@/utils/store/central"; -import { createFileRoute } from "@tanstack/react-router"; -function TabPanel(props) { - const { children, value, index, ...other } = props; - - return ( - - ); -} - -TabPanel.propTypes = { - children: PropTypes.node, - index: PropTypes.number.isRequired, - value: PropTypes.number.isRequired, -}; - -function a11yProps(index) { - return { - id: `full-width-tab-${index}`, - "aria-controls": `full-width-tabpanel-${index}`, - }; -} - -export const Route = createFileRoute("/_api/playlist/$id")({ - component: PlaylistTitlePage, -}); - -function PlaylistTitlePage() { - const { id } = Route.useParams(); - const api = Route.useRouteContext().api; - - const user = useCentralStore((s) => s.currentUser); - - const item = useQuery({ - queryKey: ["item", id], - queryFn: async () => { - const result = await getUserLibraryApi(api).getItem({ - userId: user?.Id, - itemId: id, - }); - return result.data; - }, - enabled: !!user?.Id, - networkMode: "always", - refetchOnWindowFocus: true, - }); - - const similarItems = useQuery({ - queryKey: ["item", id, "similarItem"], - queryFn: async () => { - const result = await getLibraryApi(api).getSimilarAlbums({ - userId: user?.Id, - itemId: item.data.Id, - limit: 16, - }); - return result.data; - }, - enabled: item.isSuccess, - networkMode: "always", - refetchOnWindowFocus: true, - }); - - const musicTracks = useQuery({ - queryKey: ["item", id, "musicTracks"], - queryFn: async () => { - const result = await getPlaylistsApi(api).getPlaylistItems({ - userId: user?.Id, - playlistId: item.data.Id, - }); - return result.data; - }, - enabled: item.isSuccess, - networkMode: "always", - }); - - const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); - - useEffect(() => { - if (item.isSuccess) { - setAppBackdrop( - item.data.Type === BaseItemKind.MusicAlbum || - item.data.Type === BaseItemKind.Episode - ? `${api.basePath}/Items/${item.data.ParentBackdropItemId}/Images/Backdrop` - : `${api.basePath}/Items/${item.data.Id}/Images/Backdrop`, - item.data.Id, - ); - } - }, []); - - if (item.isPending || similarItems.isPending) { - return ( - - - - ); - } - if (item.isSuccess && similarItems.isSuccess) { - return ( -
- {musicTracks.isPending ? ( - <> - ) : ( - musicTracks.data.TotalRecordCount > 0 && - musicTracks.data.Items.map((track, index) => { - return ( - - ); - }) - )} - - {similarItems.data.TotalRecordCount > 0 && ( - - {similarItems.data.Items.map((similar, index) => { - return ( - - ); - })} - - )} -
- ); - } - if (item.isError || similarItems.isError) { - return ; - } -} - -export default PlaylistTitlePage; diff --git a/src/routes/_api/playlist/$id.tsx b/src/routes/_api/playlist/$id.tsx new file mode 100644 index 0000000..8ed0dee --- /dev/null +++ b/src/routes/_api/playlist/$id.tsx @@ -0,0 +1,250 @@ +import React, { useEffect } from "react"; + +import Box from "@mui/material/Box"; +import CircularProgress from "@mui/material/CircularProgress"; + +import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; +import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; +import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api/playlists-api"; +import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"; + +import { useQuery } from "@tanstack/react-query"; + +import { Card } from "@/components/card/card"; +import CardScroller from "@/components/cardScroller/cardScroller"; +import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; +import { useBackdropStore } from "@/utils/store/backdrop"; +import "./playlist.scss"; +import AlbumMusicTrack from "@/components/albumMusicTrack"; +import LikeButton from "@/components/buttons/likeButton"; +import PlayButton from "@/components/buttons/playButton"; +import ShowMoreText from "@/components/showMoreText"; +import TagChip from "@/components/tagChip"; +import { getTypeIcon } from "@/components/utils/iconsCollection"; +import { getRuntimeCompact } from "@/utils/date/time"; +import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; +import { useCentralStore } from "@/utils/store/central"; +import { Typography } from "@mui/material"; +import { createFileRoute } from "@tanstack/react-router"; +import { createPortal } from "react-dom"; + +export const Route = createFileRoute("/_api/playlist/$id")({ + component: PlaylistTitlePage, +}); + +function PlaylistTitlePage() { + const { id } = Route.useParams(); + const api = Route.useRouteContext().api; + + const user = useCentralStore((s) => s.currentUser); + + const item = useQuery({ + queryKey: ["item", id], + queryFn: async () => { + if (!api) return null; + const result = await getUserLibraryApi(api).getItem({ + userId: user?.Id, + itemId: id, + }); + return result.data; + }, + enabled: !!user?.Id, + networkMode: "always", + refetchOnWindowFocus: true, + }); + + const similarItems = useQuery({ + queryKey: ["item", id, "similarItem"], + queryFn: async () => { + if (!api) return null; + if (!item.data?.Id) return null; + const result = await getLibraryApi(api).getSimilarAlbums({ + userId: user?.Id, + itemId: item.data.Id, + limit: 16, + }); + return result.data; + }, + enabled: item.isSuccess, + networkMode: "always", + refetchOnWindowFocus: true, + }); + + const musicTracks = useQuery({ + queryKey: ["item", "musicTracks"], + queryFn: async () => { + if (!api) return null; + if (!item.data?.Id) return null; + const result = await getPlaylistsApi(api).getPlaylistItems({ + userId: user?.Id, + playlistId: item.data.Id, + }); + return result.data; + }, + enabled: item.isSuccess, + networkMode: "always", + }); + + const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); + + useEffect(() => { + if (item.isSuccess) { + setAppBackdrop("", ""); + } + }, []); + + if (item.isPending || similarItems.isPending) { + return ( + + + + ); + } + if (item.isSuccess && item.data && similarItems.isSuccess) { + return ( +
+
+ + {item.data?.Name} + +
+ + {(musicTracks.data?.TotalRecordCount ?? 0) > 1 + ? `${musicTracks.data?.TotalRecordCount} songs` + : "Single"} + + + {getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)} + +
+
+ + +
+
+
+
+ tag + Title + Duration +
+ {musicTracks.data?.Items?.map((track, index) => ( + + ))} +
+
+
+ {createPortal( +
+
+ {item.data.ImageTags?.Primary ? ( + {item.data.Name + ) : ( +
+ {getTypeIcon("Playlist")} +
+ )} +
+
+ {item.data.GenreItems?.map((genre) => ( + + ))} +
+
+ +
+
, + document.body, + )} + {(similarItems.data?.TotalRecordCount ?? 0) > 0 && ( + + {similarItems.data?.Items?.map((similar) => { + return ( + + ); + })} + + )} +
+ ); + } + if (item.isError || similarItems.isError) { + return ; + } +} + +export default PlaylistTitlePage; diff --git a/src/routes/_api/playlist/playlist.scss b/src/routes/_api/playlist/playlist.scss index a887609..338c185 100644 --- a/src/routes/_api/playlist/playlist.scss +++ b/src/routes/_api/playlist/playlist.scss @@ -1,5 +1,99 @@ - -.item-detail-playlist { +$border-radius: 20px; +.item-playlist { + width: 70vw; + padding-right: 2.2em; + .item-info { + display: flex; + flex-direction: column; + gap: 1.2em; + &-container { + grid-template-columns: 1fr 25%; + display: grid; + gap: 3em; + } + &-playlist-info { + gap: 1.2em; + } + &-buttons { + display: flex; + gap: 1em; + } + &-disc-header { + padding: 1em 2em; + background: hsla(0, 0, 100%, 10%); + border-radius: 100px; + gap: 1em; + margin-top: 1em; + } + } +} +.item-info-sidebar { + display: flex; + flex-direction: column; + gap: 1em; + position: fixed; + // max-height: 100vh; + top: 0; + right: 0; + width: 30vw; + padding: 4.4em; + padding-left: 2.2em; + &-image { + width: 100%; + object-fit: cover; + border-radius: $border-radius-default; + } + &-artist { + display: flex; + gap: 1em; + align-items: center; + padding: 1em 0; + color: rgb(255 255 255 / 0.7); + transition: $transition-time-default; + cursor: pointer; + text-decoration: none; + &:hover { + color: rgb(255 255 255) + } + &-image { + width: 100%; + height: 100%; + object-fit: cover; + z-index: 1; + position: relative; + &-container { + width: 3em; + aspect-ratio: 1; + border-radius: 100%; + overflow: hidden; + position: relative; + .material-symbols-rounded { + position: absolute; + top: 0; + right: 0; + width: 100%; + height: 100%; + display: flex; + align-items: center; + justify-content: center; + background: rgb(255 255 255 / 0.1); + z-index: 0; + } + } + } + &-container { + // max-height: 20em;/ + overflow-y: auto; + overflow-x: hidden; + } + } + &-overview { + overflow-y: auto; + max-height: 28vh; + padding-bottom: 2px; + } +} +.item-detail- { &-track { display: grid; grid-template-columns: 4% 1fr 80% 1fr; @@ -8,26 +102,286 @@ gap: 0.5em; width: 100%; padding: 0.25em 0; - background: rgb(255 255 255 / 0); + background: rgb(0 0 0 / 0.4); transition: background $transition-time-default; - - &:first-child, + backdrop-filter: blur(5px); + &:first-child { + border-radius: $border-radius $border-radius 8px 8px; + cursor: default !important; + } &:last-child { - border-bottom: none; + border-radius: 8px 8px $border-radius $border-radius; } - border-bottom: 1px solid rgb(255 255 255 / 0.05); + border-radius: 8px; &s { - border-radius: 10px !important; - overflow: hidden !important; - background: $clr-background-dark-opacity-0_8 !important; + background: transparent !important; + box-shadow: none !important; + display: flex; + flex-direction: column; + gap: 5px; } - &:hover { - background: rgb(255 255 255 / 0.05); + background: rgb(0 0 0 / 0.5); + cursor: pointer; } - &.playing { color: $clr-accent-default; } } } +$cardWidth: 22%; +.item-playlist.item { + .item-hero { + height: 50vh; + gap: 2em; + position: relative; + align-items: center; + &-image { + opacity: 0; + width: 100%; + object-fit: contain; + transition: opacity $transition-time-default; + &-container { + height: fit-content; + max-height: 100%; + overflow: hidden; + border-radius: $border-radius-default; + box-shadow: $shadow-card; + flex-grow: 1; + flex-shrink: 0; + position: relative; + } + &-blurhash { + position: absolute !important; + width: 100% !important; + height: 100% !important; + z-index: -1; + } + } + &-logo { + max-width: 42rem; + max-height: 10rem; + opacity: 0; + transition: opacity $transition-time-default; + object-position: bottom; + } + &-detail { + width: 100%; + align-items: flex-start; + gap: 1em; + justify-content: end; + } + &-buttons { + &-container { + align-items: center; + justify-content: space-between; + width: 100%; + } + } + &-backdrop { + width: 100vw; + height: 100vh; + object-fit: cover; + object-position: top; + opacity: 0; + transition: opacity $transition-time-default; + &-container { + filter: brightness(0.8); + position: absolute; + top: -4.4em; + left: -$page-margin; + width: 100vw; + height: calc(50vh + 4.4em); + z-index: -1; + mask-image: linear-gradient(to top, transparent, black); + -webkit-mask-image: linear-gradient(to top, + transparent, + black); + } + } + } + .item-hero { + height: 60vh; + gap: 2em; + row-gap: 1.2em; + position: relative; + align-items: flex-end; + margin-bottom: 1em; + display: grid; + grid-template-columns: $cardWidth 1fr; + grid-template-rows: 1fr auto; + &-image { + opacity: 0; + width: 100%; + object-fit: contain; + transition: opacity $transition-time-default; + &-container { + height: fit-content; + max-height: 100%; + overflow: hidden; + border-radius: $border-radius-default; + box-shadow: $shadow-card; + flex-grow: 1; + flex-shrink: 0; + position: relative; + width: 100%; + } + &-blurhash { + position: absolute !important; + width: 100% !important; + height: 100% !important; + z-index: -1; + } + &-icon { + background: linear-gradient(45deg, rgb(255 255 255 / 0.05), rgb(255 255 255 / 0.15)); + height: 100%; + display: flex; + align-items: center; + justify-content: center; + .material-symbols-rounded { + font-size: 4em; + } + } + } + &-logo { + max-width: 34rem; + max-height: 10rem; + opacity: 0; + transition: opacity $transition-time-default; + object-position: bottom; + margin-bottom: 2em; + } + &-detail { + width: 100%; + align-items: flex-start; + gap: 0.2em; + justify-content: end; + } + &-buttons { + &-container { + align-items: center; + justify-content: space-between; + width: 100%; + grid-column: 1/3; + display: grid; + grid-template-columns: inherit; + gap: 2em; + } + } + &-backdrop { + width: 100vw; + height: 100vh; + object-fit: cover; + object-position: top; + opacity: 0; + transition: opacity $transition-time-default; + &-container { + filter: brightness(0.8); + position: absolute; + top: -4.4em; + left: -$page-margin; + width: 100vw; + height: calc(54vh + 4.4em); + z-index: -1; + mask-image: linear-gradient(to top, transparent, black); + -webkit-mask-image: linear-gradient(to top, + transparent, + black); + } + } + & .play-button { + width: 100% !important; + } + } + .item-detail { + display: grid; + grid-template-columns: 1fr 35%; + justify-items: center; + align-items: start; + gap: 3em; + &-cast { + max-height: 50vh; + overflow-y: auto; + overflow-x: hidden; + mask-image: linear-gradient(to top, transparent, black 1.2em); + -webkit-mask-image: linear-gradient(to top, transparent, black 1.2em); + &-title { + position: sticky; + top: 0; + background: black; + border: 1px solid rgb(255 255 255 / 0.2); + padding: 0.35em; + border-radius: 10px; + z-index: 1; + } + &-container { + display: flex; + flex-direction: column; + gap: 1em; + } + &-grid { + display: grid; + gap: 1em; + margin-bottom: 1em; + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + &-card { + display: grid; + grid-template-columns: 6em 1fr; + gap: 0.5em; + align-items: center; + color: white !important; + text-decoration: none; + padding: 0.5em; + background: rgb(255 255 255 / 0); + transition: background $transition-time-default; + border-radius: $border-radius-default; + &:hover { + background: rgb(255 255 255 / 0.1); + } + &-image, + &-icon { + width: 6em; + height: 6em; + object-fit: cover; + border-radius: 100%; + box-shadow: $shadow-card-image; + } + &-icon { + display: flex; + align-items: center; + justify-content: center; + font-size: 1em; + background: rgb(255 255 255 / 0.1); + .material-symbols-rounded { + font-size: 3em; + } + } + } + } + &-link { + color: white; + text-decoration-color: rgb(255 255 255 / 0.5); + &:hover { + text-decoration-color: white; + } + } + &-episodes-container { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 0.25em; + margin-top: 0.5em; + align-items: start; + justify-items: center; + } + } +} +@media (max-width: 1320px) { + .item-playlist .item-detail { + &-cast { + &-grid { + grid-template-columns: 1fr; + } + } + } +} \ No newline at end of file