mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
refactor artist header to better handle artist image from info endpoint
This commit is contained in:
@@ -185,12 +185,14 @@ export const AlbumArtistDetailHeader = forwardRef<HTMLDivElement, AlbumArtistDet
|
|||||||
const showRating = showRatings && detailQuery?.data?._serverType === ServerType.NAVIDROME;
|
const showRating = showRatings && detailQuery?.data?._serverType === ServerType.NAVIDROME;
|
||||||
|
|
||||||
const selectedImageUrl = useMemo(() => {
|
const selectedImageUrl = useMemo(() => {
|
||||||
return detailQuery.data?.imageUrl || artistInfoQuery.data?.imageUrl || imageUrl;
|
return detailQuery.data?.imageUrl || imageUrl;
|
||||||
}, [artistInfoQuery.data?.imageUrl, detailQuery.data?.imageUrl, imageUrl]);
|
}, [detailQuery.data?.imageUrl, imageUrl]);
|
||||||
|
|
||||||
|
const alternateImageUrl = artistInfoQuery.data?.imageUrl;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LibraryHeader
|
<LibraryHeader
|
||||||
imageUrl={selectedImageUrl}
|
imageUrl={selectedImageUrl || alternateImageUrl}
|
||||||
item={{
|
item={{
|
||||||
imageId: detailQuery.data?.imageId,
|
imageId: detailQuery.data?.imageId,
|
||||||
imageUrl: detailQuery.data?.imageUrl,
|
imageUrl: detailQuery.data?.imageUrl,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { useQuery, useQueryClient, useSuspenseQueries } from '@tanstack/react-query';
|
import { useSuspenseQueries } from '@tanstack/react-query';
|
||||||
import { Suspense, useEffect, useRef } from 'react';
|
import { Suspense, useRef } from 'react';
|
||||||
import { useParams } from 'react-router';
|
import { useParams } from 'react-router';
|
||||||
|
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
|
||||||
import { useItemImageUrl } from '/@/renderer/components/item-image/item-image';
|
import { useItemImageUrl } from '/@/renderer/components/item-image/item-image';
|
||||||
import { NativeScrollArea } from '/@/renderer/components/native-scroll-area/native-scroll-area';
|
import { NativeScrollArea } from '/@/renderer/components/native-scroll-area/native-scroll-area';
|
||||||
import { albumQueries } from '/@/renderer/features/albums/api/album-api';
|
import { albumQueries } from '/@/renderer/features/albums/api/album-api';
|
||||||
@@ -20,12 +19,7 @@ import { PageErrorBoundary } from '/@/renderer/features/shared/components/page-e
|
|||||||
import { useFastAverageColor } from '/@/renderer/hooks';
|
import { useFastAverageColor } from '/@/renderer/hooks';
|
||||||
import { useArtistBackground, useCurrentServer, useCurrentServerId } from '/@/renderer/store';
|
import { useArtistBackground, useCurrentServer, useCurrentServerId } from '/@/renderer/store';
|
||||||
import { Spinner } from '/@/shared/components/spinner/spinner';
|
import { Spinner } from '/@/shared/components/spinner/spinner';
|
||||||
import {
|
import { AlbumListSort, LibraryItem, SortOrder } from '/@/shared/types/domain-types';
|
||||||
AlbumArtistDetailResponse,
|
|
||||||
AlbumListSort,
|
|
||||||
LibraryItem,
|
|
||||||
SortOrder,
|
|
||||||
} from '/@/shared/types/domain-types';
|
|
||||||
|
|
||||||
const AlbumArtistDetailRouteContent = () => {
|
const AlbumArtistDetailRouteContent = () => {
|
||||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -33,7 +27,6 @@ const AlbumArtistDetailRouteContent = () => {
|
|||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
const serverId = useCurrentServerId();
|
const serverId = useCurrentServerId();
|
||||||
const { artistBackground, artistBackgroundBlur } = useArtistBackground();
|
const { artistBackground, artistBackgroundBlur } = useArtistBackground();
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
const { albumArtistId, artistId } = useParams() as {
|
const { albumArtistId, artistId } = useParams() as {
|
||||||
albumArtistId?: string;
|
albumArtistId?: string;
|
||||||
@@ -42,26 +35,6 @@ const AlbumArtistDetailRouteContent = () => {
|
|||||||
|
|
||||||
const routeId = (artistId || albumArtistId) as string;
|
const routeId = (artistId || albumArtistId) as string;
|
||||||
|
|
||||||
const artistInfoQuery = useQuery({
|
|
||||||
...artistsQueries.albumArtistInfo({
|
|
||||||
query: { id: routeId, limit: 10 },
|
|
||||||
serverId: server?.id,
|
|
||||||
}),
|
|
||||||
enabled: Boolean(server?.id && routeId),
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const data = artistInfoQuery.data;
|
|
||||||
if (!data?.imageUrl || !server?.id || !routeId) return;
|
|
||||||
queryClient.setQueryData(
|
|
||||||
queryKeys.albumArtists.detail(server.id, { id: routeId }),
|
|
||||||
(prev: AlbumArtistDetailResponse | undefined) => {
|
|
||||||
if (!prev) return prev;
|
|
||||||
return { ...prev, imageUrl: data.imageUrl ?? prev.imageUrl };
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}, [artistInfoQuery.data, queryClient, routeId, server?.id]);
|
|
||||||
|
|
||||||
const [detailQuery, albumsQuery] = useSuspenseQueries({
|
const [detailQuery, albumsQuery] = useSuspenseQueries({
|
||||||
queries: [
|
queries: [
|
||||||
artistsQueries.albumArtistDetail({ query: { id: routeId }, serverId: server?.id }),
|
artistsQueries.albumArtistDetail({ query: { id: routeId }, serverId: server?.id }),
|
||||||
|
|||||||
Reference in New Issue
Block a user