diff --git a/src/components/buttons/playButton.tsx b/src/components/buttons/playButton.tsx index 85494ab..d63d3a5 100644 --- a/src/components/buttons/playButton.tsx +++ b/src/components/buttons/playButton.tsx @@ -204,14 +204,14 @@ const PlayButton = ({ 0; } if ( - result.data.Items?.[index]?.Id && + result.data.Items?.[index].Id && result.data.Items?.[index].MediaSources?.[0]?.Id ) { mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({ audioStreamIndex: currentAudioTrack, subtitleStreamIndex: currentSubTrack === "nosub" ? -1 : currentSubTrack, - itemId: result.data.Items?.[index].Id ?? "", + itemId: result.data.Items[index].Id ?? "", startTimeTicks: result.data.Items?.[0].UserData?.PlaybackPositionTicks, userId: userId, @@ -226,6 +226,10 @@ const PlayButton = ({ itemId: result.data.Items?.[index].Id ?? "", }) )?.data; + } else { + throw new Error( + `No media source id provieded for the episode. Return values are seriesId = ${result.data.Items?.[index].Id}, mediaSourceId = ${result.data.Items?.[index].MediaSources?.[0]?.Id}, index = ${index}`, + ); } break; case BaseItemKind.Playlist: @@ -267,6 +271,25 @@ const PlayButton = ({ sortOrder: [SortOrder.Ascending], sortBy: ["IndexNumber"], }); + if ( + result.data.Items?.[index]?.Id && + result.data.Items?.[index].MediaSources?.[0]?.Id + ) { + mediaSource = await getMediaInfoApi(api).getPostedPlaybackInfo({ + audioStreamIndex: currentAudioTrack, + subtitleStreamIndex: + currentSubTrack === "nosub" ? -1 : currentSubTrack, + itemId: result.data.Items?.[index].Id ?? "", + startTimeTicks: + result.data.Items?.[0].UserData?.PlaybackPositionTicks, + userId: userId, + mediaSourceId: + result.data.Items?.[index].MediaSources?.[0].Id ?? "", + playbackInfoDto: { + DeviceProfile: playbackProfile, + }, + }); + } break; case BaseItemKind.Photo: { @@ -383,6 +406,11 @@ const PlayButton = ({ result?.item.Items[episodeIndex].IndexNumber ?? 0 } ${result?.item.Items[episodeIndex].Name}`; } + + if (itemType === "BoxSet") { + itemName = result.item.Items[0].Name; + } + // Subtitle const subtitle = getSubtitle( currentSubTrack, diff --git a/src/routes/_api/album/$id.tsx b/src/routes/_api/album/$id.tsx index 3ebf1be..5bba028 100644 --- a/src/routes/_api/album/$id.tsx +++ b/src/routes/_api/album/$id.tsx @@ -1,4 +1,4 @@ -import React, { useLayoutEffect, useMemo, useRef } from "react"; +import React, { useLayoutEffect, useMemo } from "react"; import Box from "@mui/material/Box"; import CircularProgress from "@mui/material/CircularProgress"; @@ -26,8 +26,10 @@ import { useBackdropStore } from "@/utils/store/backdrop"; import "./album.scss"; import AlbumMusicTrack from "@/components/albumMusicTrack"; +import ShowMoreText from "@/components/showMoreText"; import TagChip from "@/components/tagChip"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; +import { useApiInContext } from "@/utils/store/api"; import { useCentralStore } from "@/utils/store/central"; import { Chip } from "@mui/material"; import { Link, createFileRoute } from "@tanstack/react-router"; @@ -39,20 +41,14 @@ export const Route = createFileRoute("/_api/album/$id")({ function MusicAlbumTitlePage() { const { id } = Route.useParams(); - const api = Route.useRouteContext().api; - - if (!api) { - throw new Error("API not found", { - cause: - "API is not set in the context, maybe it is not initialized before the component is rendered.", - }); - } + const api = useApiInContext((s) => s.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, @@ -67,7 +63,7 @@ function MusicAlbumTitlePage() { const similarItems = useQuery({ queryKey: ["item", id, "similarItem"], queryFn: async () => { - if (item.data?.Id) { + if (api && item.data?.Id) { const result = await getLibraryApi(api).getSimilarAlbums({ userId: user?.Id, itemId: item.data?.Id, @@ -75,6 +71,7 @@ function MusicAlbumTitlePage() { }); return result.data; } + return null; }, enabled: item.isSuccess, networkMode: "always", @@ -84,6 +81,7 @@ function MusicAlbumTitlePage() { const musicTracks = useQuery({ queryKey: ["item", "musicTracks", id], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ userId: user?.Id, parentId: item.data?.Id, @@ -93,7 +91,7 @@ function MusicAlbumTitlePage() { }); return result.data; }, - enabled: item.isSuccess && item.data.Type === BaseItemKind.MusicAlbum, + enabled: item.isSuccess && item.data?.Type === BaseItemKind.MusicAlbum, networkMode: "always", }); @@ -117,14 +115,12 @@ function MusicAlbumTitlePage() { useLayoutEffect(() => { if (item.isSuccess) { setAppBackdrop( - `${api?.basePath}/Items/${item.data.ParentBackdropItemId}/Images/Backdrop`, - item.data.Id, + `${api?.basePath}/Items/${item.data?.ParentBackdropItemId}/Images/Backdrop`, + item.data?.Id, ); } }, [item.isSuccess]); - const pageRef = useRef(null); - if (item.isPending || similarItems.isPending) { return ( ); } - if (item.isSuccess && similarItems.isSuccess) { + if (item.isSuccess && item.data && similarItems.isSuccess) { return ( -
+
- {item.data.Name} + {item.data?.Name}
{/* @ts-ignore - Using Link as component */} - - artist - - } - label={item.data.AlbumArtist} - /> + > + + artist + + } + label={item.data.AlbumArtist} + /> + {item.data.ProductionYear} {(musicTracks.data?.TotalRecordCount ?? 0) > 1 ? `${musicTracks.data?.TotalRecordCount} songs` - : "1 song"} + : "Single"} {getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)} @@ -262,9 +257,9 @@ function MusicAlbumTitlePage() { className="item-info-sidebar-image" alt={item.data.Name ?? "Album"} src={ - item.data.Id && + api && getImageUrlsApi(api).getItemImageUrlById( - item.data.Id, + item.data.Id ?? "", "Primary", { tag: item.data.ImageTags.Primary, @@ -287,34 +282,11 @@ function MusicAlbumTitlePage() { ))}
-
- {item.data.ArtistItems?.map((artist) => ( - -
- {artist.Name - artist -
- {artist.Name} - - ))} +
+
, document.body, diff --git a/src/routes/_api/album/album.scss b/src/routes/_api/album/album.scss index b768fed..76de2ca 100644 --- a/src/routes/_api/album/album.scss +++ b/src/routes/_api/album/album.scss @@ -34,7 +34,7 @@ $border-radius: 20px; flex-direction: column; gap: 1em; position: fixed; - max-height: 100vh; + // max-height: 100vh; top: 0; right: 0; width: 30vw; @@ -89,6 +89,11 @@ $border-radius: 20px; overflow-x: hidden; } } + &-overview { + overflow-y: auto; + max-height: 28vh; + padding-bottom: 2px; + } } .item-detail-album { diff --git a/src/routes/_api/artist/$id.tsx b/src/routes/_api/artist/$id.tsx index 28968af..842be4e 100644 --- a/src/routes/_api/artist/$id.tsx +++ b/src/routes/_api/artist/$id.tsx @@ -1,5 +1,10 @@ -import PropTypes from "prop-types"; -import React, { useState, useEffect, useLayoutEffect, useRef } from "react"; +import React, { + useState, + useEffect, + useLayoutEffect, + useRef, + type ReactNode, +} from "react"; import Box from "@mui/material/Box"; import CircularProgress from "@mui/material/CircularProgress"; @@ -17,7 +22,6 @@ import { SortOrder, } from "@jellyfin/sdk/lib/generated-client"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-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"; @@ -26,7 +30,6 @@ import LikeButton from "@/components/buttons/likeButton"; import { Card } from "@/components/card/card"; import { Blurhash } from "react-blurhash"; -import meshBg from "@/assets/herobg.png"; import { ArtistAlbum } from "@/components/layouts/artist/artistAlbum"; import MusicTrack from "@/components/musicTrack"; import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice"; @@ -40,7 +43,14 @@ import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import { useCentralStore } from "@/utils/store/central"; import { createFileRoute } from "@tanstack/react-router"; -function TabPanel(props) { + +type TabPanelProp = { + children: ReactNode; + index: number; + value: number; +}; + +function TabPanel(props: TabPanelProp) { const { children, value, index, ...other } = props; return ( @@ -57,12 +67,6 @@ function TabPanel(props) { ); } -TabPanel.propTypes = { - children: PropTypes.node, - index: PropTypes.number.isRequired, - value: PropTypes.number.isRequired, -}; - export const Route = createFileRoute("/_api/artist/$id")({ component: ArtistTitlePage, }); @@ -76,10 +80,10 @@ function ArtistTitlePage() { const item = useQuery({ queryKey: ["item", id], queryFn: async () => { + if (!api) return null; const result = await getUserLibraryApi(api).getItem({ userId: user?.Id, itemId: id, - fields: [ItemFields.Crew], }); return result.data; }, @@ -91,8 +95,9 @@ function ArtistTitlePage() { const artistDiscography = useQuery({ queryKey: ["item", id, "artist", "discography"], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ - albumArtistIds: [item.data.Id], + albumArtistIds: [item.data?.Id ?? ""], sortBy: ["PremiereDate", "ProductionYear", "SortName"], sortOrder: [SortOrder.Descending], recursive: true, @@ -102,14 +107,16 @@ function ArtistTitlePage() { }); return result.data; }, - enabled: item.isSuccess && item.data.Type === BaseItemKind.MusicArtist, + enabled: item.isSuccess && item.data?.Type === BaseItemKind.MusicArtist, }); const artistSongs = useQuery({ queryKey: ["item", id, "artist", "songs"], queryFn: async () => { + if (!api) return null; + const result = await getItemsApi(api).getItems({ - artistIds: [item.data.Id], + artistIds: [item.data?.Id ?? ""], sortBy: ["PremiereDate", "ProductionYear", "SortName"], sortOrder: [SortOrder.Ascending], recursive: true, @@ -119,15 +126,16 @@ function ArtistTitlePage() { }); return result.data; }, - enabled: item.isSuccess && item.data.Type === BaseItemKind.MusicArtist, + enabled: item.isSuccess && item.data?.Type === BaseItemKind.MusicArtist, }); const artistAppearances = useQuery({ queryKey: ["item", id, "artist", "appearences"], queryFn: async () => { + if (!api) return null; const result = await getItemsApi(api).getItems({ - contributingArtistIds: [item.data.Id], - excludeItemIds: [item.data.Id], + contributingArtistIds: [item.data?.Id ?? ""], + excludeItemIds: [item.data?.Id ?? ""], sortBy: ["PremiereDate", "ProductionYear", "SortName"], sortOrder: [SortOrder.Descending], recursive: true, @@ -136,7 +144,7 @@ function ArtistTitlePage() { }); return result.data; }, - enabled: item.isSuccess && item.data.Type === BaseItemKind.MusicArtist, + enabled: item.isSuccess && item.data?.Type === BaseItemKind.MusicArtist, }); const artistTabs = [ @@ -150,7 +158,10 @@ function ArtistTitlePage() { if ( artistDiscography.isSuccess && artistSongs.isSuccess && - artistAppearances.isSuccess + artistAppearances.isSuccess && + artistDiscography.data && + artistSongs.data && + artistAppearances.data ) { if (artistDiscography.data.TotalRecordCount !== 0) { setActiveArtistTab(0); @@ -170,9 +181,9 @@ function ArtistTitlePage() { const { setBackdrop } = useBackdropStore(); useEffect(() => { - if (item.isSuccess) { + if (item.isSuccess && item.data) { setBackdrop( - `${api.basePath}/Items/${item.data.Id}/Images/Backdrop`, + `${api?.basePath}/Items/${item.data.Id}/Images/Backdrop`, item.data.Id, ); } @@ -200,7 +211,7 @@ function ArtistTitlePage() { ); } - if (item.isSuccess) { + if (item.isSuccess && item.data) { return (
{ - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} style={{ y: parallax, @@ -243,53 +257,59 @@ function ArtistTitlePage() { aspectRatio: item.data.PrimaryImageAspectRatio ?? 1, }} > - {Object.keys(item.data.ImageTags).includes("Primary") ? ( - <> + {item.data.ImageTags?.Primary ? ( +
{item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-image" /> - +
) : (
- {getTypeIcon(item.data.Type)} + {getTypeIcon(item.data.Type ?? "MusicArtist")}
)}
- {Object.keys(item.data.ImageTags).includes("Logo") ? ( + {item.data.ImageTags?.Logo ? ( {item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-logo" /> @@ -323,7 +343,11 @@ function ArtistTitlePage() { }} > {item.data.ExternalUrls?.map((url) => ( - + ))}
@@ -333,22 +357,22 @@ function ArtistTitlePage() { }} > {item.data.PremiereDate && ( - <> +
Born {new Date(item.data.PremiereDate).toDateString()} - +
)} {item.data.EndDate && ( - <> +
Death {new Date(item.data.EndDate).toDateString()} - +
)}
@@ -357,7 +381,7 @@ function ArtistTitlePage() { { + onChange={(_, newVal) => { if (newVal > activeArtistTab) { setAnimationDirection("forward"); } else if (newVal < activeArtistTab) { @@ -398,8 +422,8 @@ function ArtistTitlePage() { ease: "anticipate", }} > - {artistDiscography.isSuccess && - artistDiscography.data.Items?.map((tabitem) => { + {user && + artistDiscography.data?.Items?.map((tabitem) => { return ( {artistSongs.isSuccess && - artistSongs.data.Items?.map((tabitem) => { + artistSongs.data?.Items?.map((tabitem) => { return ( {artistAppearances.isSuccess && - artistAppearances.data.Items?.map((tabitem) => { + artistAppearances.data?.Items?.map((tabitem) => { return (
); } - if (item.isSuccess && similarItems.isSuccess) { + if (item.isSuccess && item.data && similarItems.isSuccess) { return ( {item.data.BackdropImageTags?.length ? ( { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} style={{ y: parallax, @@ -198,11 +186,11 @@ function BoxSetTitlePage() { /> ) : ( { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} style={{ y: parallax, @@ -216,53 +204,60 @@ function BoxSetTitlePage() { aspectRatio: item.data.PrimaryImageAspectRatio ?? 1, }} > - {Object.keys(item.data.ImageTags).includes("Primary") ? ( - <> + {item.data.ImageTags?.Primary && + item.data.ImageBlurHashes?.Primary ? ( +
{item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-image" /> - +
) : (
- {getTypeIcon(item.data.Type)} + {getTypeIcon(item.data.Type ?? "BoxSet")}
)}
- {Object.keys(item.data.ImageTags).includes("Logo") ? ( + {item.data.ImageTags?.Logo ? ( {item.data.Name} { - e.currentTarget.style.opacity = 1; + e.currentTarget.style.opacity = "1"; }} className="item-hero-logo" /> @@ -357,7 +352,7 @@ function BoxSetTitlePage() { {endsAt( item.data.RunTimeTicks - - item.data.UserData.PlaybackPositionTicks, + (item.data.UserData?.PlaybackPositionTicks ?? 0), )} )} @@ -370,9 +365,7 @@ function BoxSetTitlePage() {
@@ -420,15 +413,19 @@ function BoxSetTitlePage() { marginTop: "1em", }} > - {item.data.ExternalUrls.map((url) => ( - + {item.data.ExternalUrls?.map((url) => ( + ))}
- {collectionItems.data.TotalRecordCount > 0 && ( + {(collectionItems.data?.TotalRecordCount ?? 0) > 0 && ( - {collectionItems.data.Items.map((similar, index) => { + {collectionItems.data?.Items?.map((similar) => { return ( ); })} )} - {similarItems.data.TotalRecordCount > 0 && ( + {similarItems.data?.TotalRecordCount && ( - {similarItems.data.Items.map((similar, index) => { + {similarItems.data?.Items?.map((similar) => { return ( ); })}