mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 02:43:33 +00:00
Add ability to add/remove songs from playlist (#17)
* Add api for add/remove playlist items * Add playlistItemId property to normalized Song - This is used for Navidrome to delete songs from playlists * Add mutations for add/remove from playlist * Add context modal for playlist add * Add remove from playlist from context menu * Set jellyfin to use playlistItemId * Adjust font sizing * Add playlist add from detail pages * Bump mantine to v6-alpha.2
This commit is contained in:
parent
be39c2bc1f
commit
59f4f43e84
23 changed files with 1120 additions and 982 deletions
|
|
@ -0,0 +1,28 @@
|
|||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { HTTPError } from 'ky';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { AddToPlaylistArgs, RawAddToPlaylistResponse } from '/@/renderer/api/types';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { useCurrentServer } from '/@/renderer/store';
|
||||
|
||||
export const useAddToPlaylist = (options?: MutationOptions) => {
|
||||
const queryClient = useQueryClient();
|
||||
const server = useCurrentServer();
|
||||
|
||||
return useMutation<RawAddToPlaylistResponse, HTTPError, Omit<AddToPlaylistArgs, 'server'>, null>({
|
||||
mutationFn: (args) => api.controller.addToPlaylist({ ...args, server }),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries(queryKeys.playlists.list(server?.id || ''), { exact: false });
|
||||
|
||||
queryClient.invalidateQueries(
|
||||
queryKeys.playlists.detail(server?.id || '', variables.query.id),
|
||||
);
|
||||
|
||||
queryClient.invalidateQueries(
|
||||
queryKeys.playlists.detailSongList(server?.id || '', variables.query.id),
|
||||
);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { HTTPError } from 'ky';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { RawRemoveFromPlaylistResponse, RemoveFromPlaylistArgs } from '/@/renderer/api/types';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { useCurrentServer } from '/@/renderer/store';
|
||||
|
||||
export const useRemoveFromPlaylist = (options?: MutationOptions) => {
|
||||
const queryClient = useQueryClient();
|
||||
const server = useCurrentServer();
|
||||
|
||||
return useMutation<
|
||||
RawRemoveFromPlaylistResponse,
|
||||
HTTPError,
|
||||
Omit<RemoveFromPlaylistArgs, 'server'>,
|
||||
null
|
||||
>({
|
||||
mutationFn: (args) => api.controller.removeFromPlaylist({ ...args, server }),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries(queryKeys.playlists.list(server?.id || ''), { exact: false });
|
||||
|
||||
queryClient.invalidateQueries(
|
||||
queryKeys.playlists.detail(server?.id || '', variables.query.id),
|
||||
);
|
||||
|
||||
queryClient.invalidateQueries(
|
||||
queryKeys.playlists.detailSongList(server?.id || '', variables.query.id),
|
||||
);
|
||||
},
|
||||
...options,
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue