From 47ded84c48f32726c0e1baadff84af5f7cdf78de Mon Sep 17 00:00:00 2001 From: Prayag Prajapati Date: Mon, 29 Jul 2024 10:04:31 +0530 Subject: [PATCH] feat: add new album page --- .vscode/extensions.json | 5 +- biome.json | 3 +- src/components/appBar/appBar.tsx | 2 +- src/components/buttons/playButton.tsx | 8 +- src/components/tagChip/index.tsx | 20 + src/components/tagChip/tagChip.scss | 19 + ...consCollection.jsx => iconsCollection.tsx} | 2 +- src/routes/_api.tsx | 9 +- src/routes/_api/album/$id.tsx | 443 +++++++----------- src/routes/_api/album/album.scss | 206 +++++--- src/routes/_api/library/$id.tsx | 32 ++ src/styles/global.scss | 4 + src/utils/store/audioPlayback.ts | 14 + 13 files changed, 413 insertions(+), 354 deletions(-) create mode 100644 src/components/tagChip/index.tsx create mode 100644 src/components/tagChip/tagChip.scss rename src/components/utils/{iconsCollection.jsx => iconsCollection.tsx} (98%) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4a151ee..aef9f78 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,8 +2,9 @@ "recommendations": [ "biomejs.biome", "github.vscode-github-actions", - "esbenp.prettier-vscode", "swellaby.rust-pack", - "1yib.rust-bundle" + "1yib.rust-bundle", + "sibiraj-s.vscode-scss-formatter", + "tauri-apps.tauri-vscode" ] } \ No newline at end of file diff --git a/biome.json b/biome.json index c7a8579..0c15368 100644 --- a/biome.json +++ b/biome.json @@ -30,7 +30,8 @@ "src/**/*.tsx", "src/**/*.jsx", "src/**/*.js", - "*.json" + "*.json", + "*.scss" ], "ignoreUnknown": true } diff --git a/src/components/appBar/appBar.tsx b/src/components/appBar/appBar.tsx index 7bb8942..bf370f6 100644 --- a/src/components/appBar/appBar.tsx +++ b/src/components/appBar/appBar.tsx @@ -85,7 +85,7 @@ export const AppBar = () => { const usr = await getUserApi(api).getCurrentUser(); return usr.data; }, - enabled: display && Boolean(api.accessToken), + enabled: display && Boolean(api?.accessToken), throwOnError: true, }); const libraries = useQuery({ diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 3c1d98d..2e426a7 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -400,7 +400,7 @@ const PlayButton = ({ color="white" size={size} > - {itemUserData.PlaybackPositionTicks + {itemUserData?.PlaybackPositionTicks ? "Continue Watching" : item?.Type === "MusicAlbum" || item?.Type === "Audio" || @@ -412,8 +412,8 @@ const PlayButton = ({ itemUserData.PlayedPercentage > 0 - ? itemUserData.PlayedPercentage + 100 > itemUserData?.PlayedPercentage > 0 + ? itemUserData?.PlayedPercentage : 0 } sx={{ @@ -431,7 +431,7 @@ const PlayButton = ({ color="white" /> - {itemUserData.PlaybackPositionTicks > 0 && ( + {itemUserData?.PlaybackPositionTicks > 0 && ( { + return ( + + + {label} + + + ); +}; + +export default TagChip; \ No newline at end of file diff --git a/src/components/tagChip/tagChip.scss b/src/components/tagChip/tagChip.scss new file mode 100644 index 0000000..e61eb79 --- /dev/null +++ b/src/components/tagChip/tagChip.scss @@ -0,0 +1,19 @@ +.tag { + display: flex; + padding: 0.4em 0.8em; + color: white; + text-decoration: none; + gap: 0.2em; + border: 1px solid rgb(255 255 255 / 0.3); + border-radius: 4em; + .MuiTypography-root { + white-space: nowrap; + transition: $transition-time-fast; + } + &:hover { + border-color: rgb(255 255 255 / 0.8) !important; + .MuiTypography-root { + font-weight: 400; + } + } +} \ No newline at end of file diff --git a/src/components/utils/iconsCollection.jsx b/src/components/utils/iconsCollection.tsx similarity index 98% rename from src/components/utils/iconsCollection.jsx rename to src/components/utils/iconsCollection.tsx index 5d4b8c3..5750610 100644 --- a/src/components/utils/iconsCollection.jsx +++ b/src/components/utils/iconsCollection.tsx @@ -1,7 +1,7 @@ import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client"; import React from "react"; -export const getTypeIcon = (icon) => { +export const getTypeIcon = (icon: BaseItemKind) => { switch (icon) { case "Home": return
home
; diff --git a/src/routes/_api.tsx b/src/routes/_api.tsx index e6b38f3..3109807 100644 --- a/src/routes/_api.tsx +++ b/src/routes/_api.tsx @@ -47,13 +47,16 @@ export const Route = createFileRoute("/_api")({ }, }); } - return { api: apiTemp }; + // return { api: apiTemp }; } context.createApi(currentServer?.address, userOnDisk.AccessToken); } else { - const apiTemp = context.jellyfinSDK.createApi(currentServer?.address, null); + const apiTemp = context.jellyfinSDK.createApi( + currentServer?.address, + null, + ); context.createApi(currentServer?.address, undefined); // Creates Api - return { api: apiTemp }; + // return { api: apiTemp }; } } } else if (context.api) { diff --git a/src/routes/_api/album/$id.tsx b/src/routes/_api/album/$id.tsx index 52ef240..2fdc936 100644 --- a/src/routes/_api/album/$id.tsx +++ b/src/routes/_api/album/$id.tsx @@ -11,7 +11,11 @@ import Typography from "@mui/material/Typography"; import useParallax from "@/utils/hooks/useParallax"; import { motion, useScroll } from "framer-motion"; -import { BaseItemKind, SortOrder } from "@jellyfin/sdk/lib/generated-client"; +import { + type BaseItemDto, + BaseItemKind, + SortOrder, +} from "@jellyfin/sdk/lib/generated-client"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; @@ -21,7 +25,11 @@ import { Blurhash } from "react-blurhash"; import { useQuery } from "@tanstack/react-query"; -import { getRuntime } from "@/utils/date/time"; +import { + getRuntime, + getRuntimeCompact, + getRuntimeMusic, +} from "@/utils/date/time"; import { Card } from "@/components/card/card"; import { CardScroller } from "@/components/cardScroller/cardScroller"; @@ -33,11 +41,16 @@ import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; import ShowMoreText from "@/components/showMoreText"; import { getTypeIcon } from "@/components/utils/iconsCollection"; -import { useAudioPlayback } from "@/utils/store/audioPlayback"; +import { + generateAudioStreamUrl, + playAudio, + useAudioPlayback, +} from "@/utils/store/audioPlayback"; import { useBackdropStore } from "@/utils/store/backdrop"; import "./album.scss"; import IconLink from "@/components/iconLink"; +import TagChip from "@/components/tagChip"; import { Link, createFileRoute } from "@tanstack/react-router"; function TabPanel(props) { @@ -118,7 +131,7 @@ function MusicAlbumTitlePage() { }); const musicTracks = useQuery({ - queryKey: ["item", id, "musicTracks"], + queryKey: ["item", "musicTracks", id], queryFn: async () => { const result = await getItemsApi(api).getItems({ userId: user.data?.Id, @@ -132,31 +145,6 @@ function MusicAlbumTitlePage() { networkMode: "always", }); - const [ - currentTrackItem, - setCurrentAudioTrack, - setAudioUrl, - setAudioDisplay, - setAudioItem, - setAudioTracks, - ] = useAudioPlayback((state) => [ - state.item, - state.setCurrentTrack, - state.setUrl, - state.setDisplay, - state.setItem, - state.setTracks, - ]); - const playTrack = (index) => { - setAudioTracks(musicTracks.data.Items); - setCurrentAudioTrack(index); - setAudioUrl( - `${api.basePath}/Audio/${musicTracks.data.Items[index].Id}/universal?deviceId=${api.deviceInfo.id}&userId=${user.data.Id}&api_key=${api.accessToken}`, - ); - setAudioItem(musicTracks.data.Items[index]); - setAudioDisplay(true); - }; - const [setAppBackdrop] = useBackdropStore((state) => [state.setBackdrop]); useLayoutEffect(() => { @@ -175,6 +163,22 @@ function MusicAlbumTitlePage() { }); const parallax = useParallax(scrollYProgress, 50); + const handlePlayback = ( + index: number, + item: BaseItemDto, + queue: BaseItemDto[], + ) => { + const url = generateAudioStreamUrl( + item.Id, + user.data?.Id, + api.deviceInfo.id, + api.basePath, + ); + playAudio(url, item, undefined, queue, index); + }; + + const currentPlayingItem = useAudioPlayback((s) => s.item); + if (item.isPending || similarItems.isPending) { return ( -
-
- {item.data.ParentBackdropImageTags?.length ? ( - { - e.currentTarget.style.opacity = 1; - }} +
+ + {item.data.Name} + +
+
+ - ) : ( - { - e.currentTarget.style.opacity = 1; - }} - style={{ - y: parallax, - }} - /> - )} + > + artist + + {item.data.AlbumArtist} +
+ + {item.data.ProductionYear} + + + {musicTracks.data?.TotalRecordCount > 1 + ? `${musicTracks.data?.TotalRecordCount} songs` + : `1 song`} + + + {getRuntimeCompact(item.data.CumulativeRunTimeTicks)} +
-
- {Object.keys(item.data.ImageTags).includes("Primary") ? ( - <> - - {item.data.Name} { - e.currentTarget.style.opacity = 1; - }} - className="item-hero-image" - /> - +
+ + +
+
+
+ tag + Title + Duration +
+ {musicTracks.data?.Items?.map((track) => ( +
+ handlePlayback( + track.IndexNumber, + track, + musicTracks.data.Items, + ) + } + > +
+ + play_arrow + + + {track.IndexNumber ?? "-"} + +
+
+ + {track.Name} + + + {track.Artists?.join(", ")} + +
+ {getRuntimeMusic(track.RunTimeTicks)} +
+ +
+
+ ))} +
+
+
+
+ {item.data.ImageTags?.Primary ? ( + {item.data.Name ) : ( -
- {getTypeIcon(item.data.Type)} +
+ {getTypeIcon("MusicAlbum")}
)}
-
- - {item.data.Name} - - - - - artist - - } - /> - {item.data.PremiereDate && ( - - {item.data.ProductionYear ?? ""} - - )} - - {item.data.ChildCount > 1 - ? `${item.data.ChildCount} Tracks` - : `${item.data.ChildCount} Track`} - - {item.data.RunTimeTicks && ( - - {getRuntime(item.data.RunTimeTicks)} - - )} - - {item.data.Genres?.slice(0, 4).join(" / ")} - - -
- -
-
- -
-
- -
-
-
-
-
- - -
- {item.data.ExternalUrls.map((url) => ( - - ))} -
-
-
- {item.data.ArtistItems.length > 0 && ( -
- - Artists - -
- {item.data.ArtistItems.map((artist) => ( - -
- {artist.Name} - -
- {getTypeIcon("Person")} -
-
-
- - {artist.Name} - - - {artist.Role} - -
- - ))} -
+ {item.data.GenreItems?.map((genre) => ( + + ))} +
+
+ {item.data.ArtistItems?.map((artist) => ( + +
+ {artist.Name + artist
- )} -
+ {artist.Name} + + ))}
- {musicTracks.isSuccess && musicTracks.data.TotalRecordCount > 0 && ( - - )} - {similarItems.data.TotalRecordCount > 0 && ( - {similarItems.data.Items.map((similar, index) => { + {similarItems.data.Items.map((similar) => { return ( )} - +
); } if (item.isError || similarItems.isError) { diff --git a/src/routes/_api/album/album.scss b/src/routes/_api/album/album.scss index 44c8890..470cb62 100644 --- a/src/routes/_api/album/album.scss +++ b/src/routes/_api/album/album.scss @@ -1,64 +1,139 @@ - $border-radius: 20px; - -.item-album{ - .item-detail-cast { - max-height: 50vh; - overflow-y: auto; - 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: $clr-background-dark; - padding: 0.35em; - border-radius: 10px; - z-index: 1; - } - &-container { +.item-album { + grid-template-columns: 1fr 25%; + display: grid; + gap: 3em; + .item-info { + display: flex; + flex-direction: column; + gap: 1.2em; + &-sidebar { display: flex; flex-direction: column; gap: 1em; - } - &-grid { - display: grid; - gap: 1em; - margin-bottom: 1em; - grid-template-columns: repeat(2, minmax(0, 1fr)) !important; - } - &-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; + position: sticky; + max-height: 100vh; + top: 0; + &-image { + width: 100%; object-fit: cover; - border-radius: 100%; - box-shadow: $shadow-card-image; + border-radius: $border-radius-default; } - &-icon { + &-artist { display: flex; + gap: 1em; align-items: center; - justify-content: center; - font-size: 1em; - background: rgb(255 255 255 / 0.1); - .material-symbols-rounded { - font-size: 3em; + 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; } } } + &-track { + display: grid; + grid-template-columns: 3em 60% 6em 1fr; + gap: 1em; + padding: 1em; + align-items: center; + cursor: pointer; + border-radius: $border-radius-default; + transition: background $transition-time-fast; + &.header { + border-bottom: 1px solid rgb(255 255 255 / 0.2); + color: rgb(255 255 255 / 0.7); + border-radius: 0 !important; + } + .index-container { + justify-self: center; + position: relative; + .material-symbols-rounded { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 2em !important; + opacity: 0; + transition: none !important; + color: $clr-accent-default; + } + } + &-info { + display: flex; + flex-direction: column; + gap: 0.1em + } + &:nth-last-of-type(even):not(.header) { + background: rgb(0 0 0 / 0.2); + } + &:hover { + background: rgb(255 255 255 / 0.1) !important; + .index-container { + // font-size: 0em; + .index { + opacity: 0; + transition: opacity 0; + } + .material-symbols-rounded { + opacity: 1; + font-size: 2.2em !important; + } + } + } + &.playing { + background: rgb(0 0 0 / 0.4) !important; + .item-info-track-info-name, .index { + color: $clr-accent-default; + font-weight: 600; + } + } + &-container { + display: flex; + flex-direction: column; + gap: 0.4em + } + } + &-album-info { + gap: 1.2em; + } + &-buttons { + display: flex; + gap: 1em; + } } } .item-detail-album { @@ -73,18 +148,14 @@ $border-radius: 20px; background: rgb(0 0 0 / 0.4); transition: background $transition-time-default; backdrop-filter: blur(5px); - &:first-child { border-radius: $border-radius $border-radius 8px 8px; cursor: default !important; - } - &:last-child { border-radius: 8px 8px $border-radius $border-radius; } border-radius: 8px; - &s { background: transparent !important; box-shadow: none !important; @@ -92,22 +163,17 @@ $border-radius: 20px; flex-direction: column; gap: 5px; } - &:hover { background: rgb(0 0 0 / 0.5); cursor: pointer; } - &.playing { color: $clr-accent-default; } } } - $cardWidth: 22%; - .item-album.item { - gap: 1em; .item-hero { height: 50vh; gap: 2em; @@ -171,11 +237,9 @@ $cardWidth: 22%; 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 - ); + -webkit-mask-image: linear-gradient(to top, + transparent, + black); } } } @@ -217,7 +281,7 @@ $cardWidth: 22%; display: flex; align-items: center; justify-content: center; - .material-symbols-rounded{ + .material-symbols-rounded { font-size: 4em; } } @@ -263,11 +327,9 @@ $cardWidth: 22%; 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 - ); + -webkit-mask-image: linear-gradient(to top, + transparent, + black); } } & .play-button { @@ -280,7 +342,6 @@ $cardWidth: 22%; justify-items: center; align-items: start; gap: 3em; - &-cast { max-height: 50vh; overflow-y: auto; @@ -291,7 +352,7 @@ $cardWidth: 22%; position: sticky; top: 0; background: black; - border:1px solid rgb(255 255 255 / 0.2) ; + border: 1px solid rgb(255 255 255 / 0.2); padding: 0.35em; border-radius: 10px; z-index: 1; @@ -358,7 +419,6 @@ $cardWidth: 22%; } } } - @media (max-width: 1320px) { .item-album .item-detail { &-cast { diff --git a/src/routes/_api/library/$id.tsx b/src/routes/_api/library/$id.tsx index 3c7453b..4d5df07 100644 --- a/src/routes/_api/library/$id.tsx +++ b/src/routes/_api/library/$id.tsx @@ -252,6 +252,38 @@ function LibraryView() { }, ]; break; + case BaseItemKind.MusicAlbum: + result = [ + { + title: "Name", + value: ItemSortBy.SortName, + }, + { + title: "Album Artist", + value: ItemSortBy.AlbumArtist, + }, + { + title: "Community Rating", + value: ItemSortBy.CommunityRating, + }, + { + title: "Critcs Rating", + value: ItemSortBy.CriticRating, + }, + { + title: "Date Added", + value: ItemSortBy.DateCreated, + }, + { + title: "Release Date", + value: ItemSortBy.PremiereDate, + }, + { + title: "Random", + value: ItemSortBy.Random, + }, + ]; + break; default: result = []; break; diff --git a/src/styles/global.scss b/src/styles/global.scss index 94970b0..e1badf0 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -294,4 +294,8 @@ h1 { .glass { background: rgb(0 0 0 / 0.3) !important; backdrop-filter: blur(40px); +} + +.opacity-07{ + opacity: 0.7; } \ No newline at end of file diff --git a/src/utils/store/audioPlayback.ts b/src/utils/store/audioPlayback.ts index a3b14bb..f966dec 100644 --- a/src/utils/store/audioPlayback.ts +++ b/src/utils/store/audioPlayback.ts @@ -30,3 +30,17 @@ export const playAudio = ( }); setQueue(queue, queueItemIndex); }; + +export const generateAudioStreamUrl = ( + itemId: string, + userId: string, + deviceId: string, + basePath: string, +) => { + const urlOptions = { + userId, + deviceId, + }; + const urlParams = new URLSearchParams(urlOptions).toString(); + return `${basePath}/Audio/${itemId}/universal?${urlParams}`; +}; \ No newline at end of file