diff --git a/src/components/albumMusicTrack/albumMusicTrack.scss b/src/components/albumMusicTrack/albumMusicTrack.scss new file mode 100644 index 0000000..5ae81d7 --- /dev/null +++ b/src/components/albumMusicTrack/albumMusicTrack.scss @@ -0,0 +1,60 @@ +.item-info-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 + } + &: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 + } +} \ No newline at end of file diff --git a/src/components/albumMusicTrack/index.tsx b/src/components/albumMusicTrack/index.tsx new file mode 100644 index 0000000..a48ce26 --- /dev/null +++ b/src/components/albumMusicTrack/index.tsx @@ -0,0 +1,113 @@ +import { + generateAudioStreamUrl, + playAudio, + useAudioPlayback, +} from "@/utils/store/audioPlayback"; +import type { + BaseItemDto, + BaseItemDtoQueryResult, +} from "@jellyfin/sdk/lib/generated-client"; +import { Typography } from "@mui/material"; +import React from "react"; + +import { getRuntimeMusic } from "@/utils/date/time"; +import { useApiInContext } from "@/utils/store/api"; +import { useCentralStore } from "@/utils/store/central"; +import { setQueue } from "@/utils/store/queue"; +import { useSnackbar } from "notistack"; +import lyricsIcon from "../../assets/icons/lyrics.svg"; +import LikeButton from "../buttons/likeButton"; + +import "./albumMusicTrack.scss"; + +type AlbumMusicTrackProps = { + track: BaseItemDto; + /** + * This is the index of the track in the musicTracks array (not to be confused with IndexNumber property of the track) + */ + trackIndex: number; + musicTracks: BaseItemDtoQueryResult | null; +}; + +export default function AlbumMusicTrack(props: AlbumMusicTrackProps) { + const { track, musicTracks, trackIndex } = props; + const [currentPlayingItem] = useAudioPlayback((state) => [state.item]); + + const user = useCentralStore((state) => state.currentUser); + const api = useApiInContext((s) => s.api); + + const { enqueueSnackbar } = useSnackbar(); + + const handlePlayback = ( + index: number, + item: BaseItemDto, + queue: BaseItemDto[], + ) => { + if (!user?.Id || !api) { + console.error("User not logged in"); + enqueueSnackbar("You need to be logged in to play music", { + variant: "error", + }); + return; + } + if (item.Id) { + const url = generateAudioStreamUrl( + item.Id, + user.Id, + api.deviceInfo.id, + api.basePath, + api.accessToken, + ); + playAudio(url, item); + setQueue(queue, index); + } + }; + return ( +
{ + if (musicTracks?.Items) { + handlePlayback(trackIndex, track, musicTracks.Items); + } + }} + > +
+ play_arrow + {track.IndexNumber ?? "-"} +
+
+ + {track.Name} + + + {track.HasLyrics && lyrics} + {track.Artists?.join(", ")} + +
+ {getRuntimeMusic(track.RunTimeTicks ?? 0)} +
+ +
+
+ ); +} \ No newline at end of file diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 727cfa6..bac38f7 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -336,11 +336,6 @@ const PlayButton = ({ enqueueSnackbar("No item ID found", { variant: "error" }); return; } - if (!result?.mediaSource?.MediaSources?.[0]?.Id) { - console.error("No media source ID found"); - enqueueSnackbar("No media source ID found", { variant: "error" }); - return; - } if (trackIndex) { // Playlist Playback @@ -363,9 +358,9 @@ const PlayButton = ({ navigate({ to: "/player/photos" }); } } else { - if (!result?.mediaSource) { - enqueueSnackbar("No media source found", { variant: "error" }); - console.error("No media source found"); + if (!result?.mediaSource?.MediaSources?.[0]?.Id) { + console.error("No media source ID found"); + enqueueSnackbar("No media source ID found", { variant: "error" }); return; } const episodeIndex = result.episodeIndex; diff --git a/src/components/card/card.tsx b/src/components/card/card.tsx index c8fce83..0cf4e8f 100644 --- a/src/components/card/card.tsx +++ b/src/components/card/card.tsx @@ -11,10 +11,10 @@ import { BaseItemKind, type ImageType, } from "@jellyfin/sdk/lib/generated-client"; +import { ErrorBoundary } from "react-error-boundary"; import LikeButton from "../buttons/likeButton"; import MarkPlayedButton from "../buttons/markPlayedButton"; import PlayButton from "../buttons/playButton"; -import ErrorBoundary from "../errorBoundary"; import { getTypeIcon } from "../utils/iconsCollection"; import "./card.scss"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; diff --git a/src/components/carouselSlide/index.tsx b/src/components/carouselSlide/index.tsx index bab1119..3751173 100644 --- a/src/components/carouselSlide/index.tsx +++ b/src/components/carouselSlide/index.tsx @@ -176,7 +176,7 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => { > {item.PremiereDate && ( - {item.ProductionYear ?? ""} + {item.ProductionYear} )} {item.OfficialRating && ( diff --git a/src/components/errorBoundary/index.jsx b/src/components/errorBoundary/index.jsx deleted file mode 100644 index 46c8fab..0000000 --- a/src/components/errorBoundary/index.jsx +++ /dev/null @@ -1,32 +0,0 @@ -import React from "react"; -class ErrorBoundary extends React.Component { - constructor(props) { - super(props); - this.state = { hasError: false }; - } - - static getDerivedStateFromError(error) { - // Update state so the next render will show the fallback UI. - return { hasError: true }; - } - - componentDidCatch(error, info) { - // Example "componentStack": - // in ComponentThatThrows (created by App) - // in ErrorBoundary (created by App) - // in div (created by App) - // in App - this.setState; - console.error(`Err in ${info} - ${error}`); - } - - render() { - if (this.state.hasError) { - // You can render any custom fallback UI - return this.props.fallback; - } - - return this.props.children; - } -} -export default ErrorBoundary; diff --git a/src/components/layouts/artist/albumArtist.scss b/src/components/layouts/artist/albumArtist.scss index be9149c..7326646 100644 --- a/src/components/layouts/artist/albumArtist.scss +++ b/src/components/layouts/artist/albumArtist.scss @@ -8,6 +8,7 @@ height: 16em; box-shadow: $shadow-card-image; position: relative; + flex-shrink: 0; &-icon { color: rgb(255 255 255 / 0.5); font-variation-settings: "FILL" 1, "wght" 300, "GRAD" 25, "opsz" 40; diff --git a/src/components/layouts/artist/artistAlbum.jsx b/src/components/layouts/artist/artistAlbum.jsx deleted file mode 100644 index 09d5fae..0000000 --- a/src/components/layouts/artist/artistAlbum.jsx +++ /dev/null @@ -1,274 +0,0 @@ -import React, { useState } from "react"; - -import MuiLink from "@mui/material/Link"; -import Paper from "@mui/material/Paper"; -import Stack from "@mui/material/Stack"; -import Typography from "@mui/material/Typography"; - -import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; -import { useQuery } from "@tanstack/react-query"; - -import { getRuntimeMusic } from "../../../utils/date/time"; - -import { SortOrder } from "@jellyfin/sdk/lib/generated-client"; -import { useAudioPlayback } from "../../../utils/store/audioPlayback"; -import LikeButton from "../../buttons/likeButton"; -import PlayButton from "../../buttons/playButton"; - -import TrackList from "../tracksList/index"; -import "./albumArtist.scss"; -import { useApiInContext } from "@/utils/store/api"; -import { Link, useRouteContext } from "@tanstack/react-router"; - -export const ArtistAlbum = ({ user, album, boxProps }) => { - const api = useApiInContext((s) => s.api); - const albumTracks = useQuery({ - queryKey: ["artist", "album", album.Id], - queryFn: async () => { - const result = await getItemsApi(api).getItems({ - userId: user.Id, - parentId: album.Id, - sortOrder: SortOrder.Ascending, - sortBy: "IndexNumber", - }); - return result.data; - }, - - 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(albumTracks.data.Items); - setCurrentAudioTrack(index); - setAudioUrl( - `${api.basePath}/Audio/${albumTracks.data.Items[index].Id}/universal?deviceId=${api.deviceInfo.id}&userId=${user.Id}&api_key=${api.accessToken}`, - ); - setAudioItem(albumTracks.data.Items[index]); - setAudioDisplay(true); - }; - - return ( -
-
- {!!album.ImageTags?.Primary && ( -
- {album.Name} (e.currentTarget.style.opacity = 1)} - /> -
- - album - -
-
- )} -
-
- - {album.ProductionYear} - - - {album.Name} - -
-
- - - -
-
-
- - {albumTracks.isSuccess && ( - - )} -
- ); -}; - -{ - /*
- - # - -
- - Name - - schedule -
- {/*albumTracks.data.Items.map((track, index) => { - return ( -
playTrack(index)} - > - - {track.IndexNumber ? track.IndexNumber : "-"} - - - - -
- - {track.Name} - - {track.AlbumArtist === "Various Artists" && ( - - {track.ArtistItems.map((artist) => artist.Name).join( - ", ", - )} - - )} -
- - {getRuntimeMusic(track.RunTimeTicks)} - -
- ); - })*/ -} diff --git a/src/components/layouts/artist/artistAlbum.tsx b/src/components/layouts/artist/artistAlbum.tsx new file mode 100644 index 0000000..f2c18d3 --- /dev/null +++ b/src/components/layouts/artist/artistAlbum.tsx @@ -0,0 +1,166 @@ +import React from "react"; + +import Typography from "@mui/material/Typography"; + +import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api"; +import { useQuery } from "@tanstack/react-query"; + +import { + type BaseItemDto, + SortOrder, + type UserDto, +} from "@jellyfin/sdk/lib/generated-client"; +import LikeButton from "../../buttons/likeButton"; +import PlayButton from "../../buttons/playButton"; + +import "./albumArtist.scss"; +import AlbumMusicTrack from "@/components/albumMusicTrack"; +import { useApiInContext } from "@/utils/store/api"; +import { Link } from "@tanstack/react-router"; + +type ArtistAlbumProps = { + user: UserDto; + album: BaseItemDto; + boxProps?: object; +}; + +export const ArtistAlbum = ({ user, album, boxProps }: ArtistAlbumProps) => { + const api = useApiInContext((s) => s.api); + const albumTracks = useQuery({ + queryKey: ["artist", "album", album.Id], + queryFn: async () => { + if (!api) return null; + const result = await getItemsApi(api).getItems({ + userId: user.Id, + parentId: album.Id, + sortOrder: [SortOrder.Ascending], + sortBy: ["IndexNumber"], + }); + return result.data; + }, + + networkMode: "always", + }); + + return ( +
+
+ {!!album.ImageTags?.Primary && ( +
+ {album.Name { + e.currentTarget.style.opacity = "1"; + }} + /> +
+ + album + +
+
+ )} +
+
+ + {album.ProductionYear} + + + + {album.Name} + + +
+
+ + + +
+
+
+ + {albumTracks.isSuccess && (albumTracks.data?.Items?.length ?? 0) > 0 && ( +
+
+ tag + Title + Duration +
+ {albumTracks.data?.Items?.map((track, index) => ( + + ))} +
+ )} +
+ ); +}; diff --git a/src/components/musicTrack/index.tsx b/src/components/musicTrack/index.tsx index c88ba4d..b563e26 100644 --- a/src/components/musicTrack/index.tsx +++ b/src/components/musicTrack/index.tsx @@ -9,7 +9,6 @@ import "./musicTrack.scss"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import { useApiInContext } from "@/utils/store/api"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client"; -import type { QueryKey } from "@tanstack/react-query"; import lyrics_icon from "../../assets/icons/lyrics.svg"; /** @@ -37,8 +36,8 @@ const MusicTrack = ({ trackIndex, className = "", }: { - item?: BaseItemDto | null; - queryKey?: QueryKey; + item: BaseItemDto; + queryKey: string[]; userId?: string | undefined; playlistItem?: boolean; playlistItemId?: string; @@ -60,16 +59,21 @@ const MusicTrack = ({
{item.Name} { - e.target.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} />
)} {item.ArtistItems?.map((artist, index) => ( - <> + {artist.Name} - {index !== item.ArtistItems.length - 1 && ( + {index !== (item.ArtistItems?.length ?? 0) - 1 && ( )} - + ))}
- - {getRuntimeMusic(item.RunTimeTicks)} + + {getRuntimeMusic(item.RunTimeTicks ?? 0)} s.currentUser); - const { enqueueSnackbar } = useSnackbar(); const item = useQuery({ queryKey: ["item", id], @@ -135,33 +125,6 @@ function MusicAlbumTitlePage() { const pageRef = useRef(null); - const handlePlayback = ( - index: number, - item: BaseItemDto, - queue: BaseItemDto[], - ) => { - if (!user?.Id || !api) { - console.error("User not logged in"); - enqueueSnackbar("You need to be logged in to play music", { - variant: "error", - }); - return; - } - if (item.Id) { - const url = generateAudioStreamUrl( - item.Id, - user.Id, - api.deviceInfo.id, - api.basePath, - api.accessToken, - ); - playAudio(url, item, undefined); - setQueue(queue, index); - } - }; - - const currentPlayingItem = useAudioPlayback((s) => s.item); - if (item.isPending || similarItems.isPending) { return ( -
-
- - {item.data.Name} - -
-
+
+ + {item.data.Name} + +
+ {/* @ts-ignore - Using Link as component */} + artist - {item.data.AlbumArtist} -
- - {item.data.ProductionYear} - - - {(musicTracks.data?.TotalRecordCount ?? 0) > 1 - ? `${musicTracks.data?.TotalRecordCount} songs` - : "1 song"} - - - {getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)} - -
-
- - -
-
- {allDiscs.length > 1 ? ( - allDiscs.map((disc) => ( -
-
- - album - - Disc {disc} -
-
- - tag - - Title - Duration -
- {musicTracks.data?.Items?.map( - (track, index) => - track.ParentIndexNumber === disc && ( -
{ - if (musicTracks.data.Items) { - handlePlayback( - index, - track, - musicTracks.data.Items, - ); - } - }} - > -
- - play_arrow - - - {track.IndexNumber ?? "-"} - -
-
- - {track.Name} - - - {track.HasLyrics && ( - lyrics - )} - {track.Artists?.join(", ")} - -
- - {getRuntimeMusic(track.RunTimeTicks ?? 0)} - -
- -
-
- ), - )} + } + label={item.data.AlbumArtist} + /> + + {item.data.ProductionYear} + + + {(musicTracks.data?.TotalRecordCount ?? 0) > 1 + ? `${musicTracks.data?.TotalRecordCount} songs` + : "1 song"} + + + {getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)} + +
+
+ + +
+
+ {allDiscs.length > 1 ? ( + allDiscs.map((disc) => ( +
+
+ + album + + Disc {disc}
- )) - ) : ( - <>
tag Title Duration
- {musicTracks.data?.Items?.map((track, index) => ( -
- musicTracks.data.Items && - handlePlayback(index, track, musicTracks.data.Items) - } - > -
- - play_arrow - - - {track.IndexNumber ?? "-"} - -
-
- - {track.Name} - - - {track.HasLyrics && ( - lyrics - )} - {track.Artists?.join(", ")} - -
- - {getRuntimeMusic(track.RunTimeTicks ?? 0)} - -
- + track.ParentIndexNumber === disc && ( + -
-
- ))} - - )} -
+ ), + )} +
+ )) + ) : ( +
+
+ tag + Title + Duration +
+ {musicTracks.data?.Items?.map((track, index) => ( + + ))} +
+ )}
+
+ {createPortal(
{item.data.ImageTags?.Primary ? ( @@ -440,12 +316,13 @@ function MusicAlbumTitlePage() { ))}
-
-
- {(similarItems.data?.TotalRecordCount ?? -1) > 0 && ( +
, + document.body, + )} + {(similarItems.data?.TotalRecordCount ?? 0) > 0 && ( {similarItems.data?.Items?.map((similar) => { diff --git a/src/routes/_api/album/album.scss b/src/routes/_api/album/album.scss index 49ad5e8..b768fed 100644 --- a/src/routes/_api/album/album.scss +++ b/src/routes/_api/album/album.scss @@ -1,5 +1,7 @@ $border-radius: 20px; .item-album { + width: 70vw; + padding-right: 2.2em; .item-info { display: flex; flex-direction: column; @@ -9,123 +11,7 @@ $border-radius: 20px; display: grid; gap: 3em; } - &-sidebar { - display: flex; - flex-direction: column; - gap: 1em; - position: sticky; - max-height: 100vh; - top: 0; - &-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; - } - } - } - &-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 - } - &: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; } @@ -142,6 +28,69 @@ $border-radius: 20px; } } } + +.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; + } + } +} + .item-detail-album { &-track { display: grid; diff --git a/src/routes/_api/artist/$id.tsx b/src/routes/_api/artist/$id.tsx index 7168797..28968af 100644 --- a/src/routes/_api/artist/$id.tsx +++ b/src/routes/_api/artist/$id.tsx @@ -31,7 +31,7 @@ import { ArtistAlbum } from "@/components/layouts/artist/artistAlbum"; import MusicTrack from "@/components/musicTrack"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; import ShowMoreText from "@/components/showMoreText"; -import { setBackdrop, useBackdropStore } from "@/utils/store/backdrop"; +import { useBackdropStore } from "@/utils/store/backdrop"; import "./artist.scss"; import IconLink from "@/components/iconLink"; @@ -168,6 +168,7 @@ function ArtistTitlePage() { const [animationDirection, setAnimationDirection] = useState("forward"); + const { setBackdrop } = useBackdropStore(); useEffect(() => { if (item.isSuccess) { setBackdrop( diff --git a/src/utils/store/audioPlayback.ts b/src/utils/store/audioPlayback.ts index 56a1f41..bca04ba 100644 --- a/src/utils/store/audioPlayback.ts +++ b/src/utils/store/audioPlayback.ts @@ -39,7 +39,7 @@ export const useAudioPlayback = createWithEqualityFn( export const playAudio = ( url: string, item: BaseItemDto | undefined | null, - playlistItemId: string | undefined, + playlistItemId?: string | undefined, ): void => { useAudioPlayback.setState({ display: true,