Skip to content

Commit

Permalink
don't pass song all the way down
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Feb 19, 2024
1 parent c947d09 commit f81bea3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/renderer/api/jellyfin/jellyfin-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ const getSimilarSongs = async (args: SimilarSongsArgs): Promise<Song[]> => {

const res = await jfApiClient(apiClientProps).getSimilarSongs({
params: {
itemId: query.song.id,
itemId: query.songId,
},
query: {
Fields: 'Genres, DateCreated, MediaSources, ParentId',
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/subsonic/subsonic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ const getSimilarSongs = async (args: SimilarSongsArgs): Promise<Song[]> => {
const res = await ssApiClient(apiClientProps).getSimilarSongs({
query: {
count: query.count,
id: query.song.id,
id: query.songId,
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ export type StructuredLyric = {

export type SimilarSongsQuery = {
count?: number;
song: Song;
songId: string;
};

export type SimilarSongsArgs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { useCurrentSong } from '/@/renderer/store';
export const FullScreenSimilarSongs = () => {
const currentSong = useCurrentSong();

return (
return currentSong ? (
<SimilarSongsList
fullScreen
song={currentSong}
/>
);
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useHandlePlayQueueAdd } from '/@/renderer/features/player/hooks/use-han
export type SimilarSongsListProps = {
count?: number;
fullScreen?: boolean;
song?: Song;
song: Song;
};

export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListProps) => {
Expand All @@ -30,8 +30,8 @@ export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListPr
cacheTime: 1000 * 60 * 2,
staleTime: 1000 * 60 * 1,
},
query: { count, song },
serverId: undefined,
query: { count, songId: song.id },
serverId: song?.serverId,
});

const columnDefs = useMemo(
Expand All @@ -52,12 +52,10 @@ export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListPr
};

return songQuery.isLoading ? (
song ? (
<Spinner
container
size={25}
/>
) : undefined
<Spinner
container
size={25}
/>
) : (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<VirtualGridAutoSizerContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import { getServerById } from '/@/renderer/store';
import { queryKeys } from '/@/renderer/api/query-keys';
import { api } from '/@/renderer/api';

export const useSimilarSongs = (args: QueryHookArgs<Partial<SimilarSongsQuery>>) => {
const { options, query } = args || {};
const server = getServerById(query.song?.serverId);
export const useSimilarSongs = (args: QueryHookArgs<SimilarSongsQuery>) => {
const { options, query, serverId } = args || {};
const server = getServerById(serverId);

return useQuery({
enabled: !!server?.id && !!query.song,
enabled: !!server,
queryFn: ({ signal }) => {
if (!server) throw new Error('Server not found');
if (!query.song) return undefined;

return api.controller.getSimilarSongs({
apiClientProps: { server, signal },
query: { count: query.count ?? 50, song: query.song },
query: { count: query.count ?? 50, songId: query.songId },
});
},
queryKey: queryKeys.albumArtists.detail(server?.id || '', query),
Expand Down

0 comments on commit f81bea3

Please sign in to comment.