mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Refactor all mutation hooks
This commit is contained in:
parent
bf3024939a
commit
68a1cb9aaa
9 changed files with 166 additions and 214 deletions
|
|
@ -1,18 +1,18 @@
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { HTTPError } from 'ky';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { RawScrobbleResponse, ScrobbleArgs } from '/@/renderer/api/types';
|
||||
import { ScrobbleResponse, ScrobbleArgs } from '/@/renderer/api/types';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { useAuthStore, useCurrentServer, useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
import { getServerById, useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
|
||||
export const useSendScrobble = (options?: MutationOptions) => {
|
||||
const currentServer = useCurrentServer();
|
||||
const incrementPlayCount = useIncrementQueuePlayCount();
|
||||
|
||||
return useMutation<RawScrobbleResponse, HTTPError, Omit<ScrobbleArgs, 'server'>, null>({
|
||||
return useMutation<ScrobbleResponse, HTTPError, Omit<ScrobbleArgs, 'server'>, null>({
|
||||
mutationFn: (args) => {
|
||||
const server = useAuthStore.getState().actions.getServer(args._serverId) || currentServer;
|
||||
return api.controller.scrobble({ ...args, server });
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.scrobble({ ...args, apiClientProps: { server } });
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
// Manually increment the play count for the song in the queue if scrobble was submitted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue