mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-14 20:40:21 +02:00
refactor api controller to internalize server fetch
This commit is contained in:
@@ -48,6 +48,7 @@ export const ShareItemContextModal = ({
|
||||
const handleSubmit = form.onSubmit(async (values) => {
|
||||
shareItemMutation.mutate(
|
||||
{
|
||||
apiClientProps: { serverId: server?.id || '' },
|
||||
body: {
|
||||
description: values.description,
|
||||
downloadable: values.allowDownloading,
|
||||
@@ -55,7 +56,6 @@ export const ShareItemContextModal = ({
|
||||
resourceIds: itemIds.join(),
|
||||
resourceType,
|
||||
},
|
||||
serverId: server?.id,
|
||||
},
|
||||
{
|
||||
onError: () => {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { AxiosError } from 'axios';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById } from '/@/renderer/store';
|
||||
import { AnyLibraryItems, ShareItemArgs, ShareItemResponse } from '/@/shared/types/domain-types';
|
||||
|
||||
export const useShareItem = (args: MutationHookArgs) => {
|
||||
@@ -12,13 +11,14 @@ export const useShareItem = (args: MutationHookArgs) => {
|
||||
return useMutation<
|
||||
ShareItemResponse,
|
||||
AxiosError,
|
||||
Omit<ShareItemArgs, 'apiClientProps' | 'server'>,
|
||||
ShareItemArgs,
|
||||
{ previous: undefined | { items: AnyLibraryItems } }
|
||||
>({
|
||||
mutationFn: (args) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.shareItem({ ...args, apiClientProps: { server } });
|
||||
return api.controller.shareItem({
|
||||
...args,
|
||||
apiClientProps: { serverId: args.apiClientProps.serverId },
|
||||
});
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user