refactor api controller to internalize server fetch

This commit is contained in:
jeffvli
2025-11-02 21:56:35 -08:00
parent 8dbaec3943
commit c7a473d864
79 changed files with 904 additions and 399 deletions
@@ -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,
});