mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 21:16:17 +02:00
refactor api controller to internalize server fetch
This commit is contained in:
@@ -3,7 +3,7 @@ import { AxiosError } from 'axios';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { MutationOptions } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
import { useIncrementQueuePlayCount } from '/@/renderer/store';
|
||||
import { usePlayEvent } from '/@/renderer/store/event.store';
|
||||
import { ScrobbleArgs, ScrobbleResponse } from '/@/shared/types/domain-types';
|
||||
|
||||
@@ -11,16 +11,12 @@ export const useSendScrobble = (options?: MutationOptions) => {
|
||||
const incrementPlayCount = useIncrementQueuePlayCount();
|
||||
const sendPlayEvent = usePlayEvent();
|
||||
|
||||
return useMutation<
|
||||
ScrobbleResponse,
|
||||
AxiosError,
|
||||
Omit<ScrobbleArgs, 'apiClientProps' | 'server'>,
|
||||
null
|
||||
>({
|
||||
return useMutation<ScrobbleResponse, AxiosError, ScrobbleArgs, null>({
|
||||
mutationFn: (args) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.scrobble({ ...args, apiClientProps: { server } });
|
||||
return api.controller.scrobble({
|
||||
...args,
|
||||
apiClientProps: { serverId: args.apiClientProps.serverId },
|
||||
});
|
||||
},
|
||||
onSuccess: (_data, variables) => {
|
||||
// Manually increment the play count for the song in the queue if scrobble was submitted
|
||||
|
||||
Reference in New Issue
Block a user