Add optimistic response to server settings mutation

This commit is contained in:
schroda
2024-09-26 13:59:37 +02:00
parent 70f8e36b6e
commit 8f4da52d1f
2 changed files with 27 additions and 1 deletions

View File

@@ -133,6 +133,7 @@ import {
SetMangaMetadataMutationVariables,
SetSourceMetadataMutation,
SetSourceMetadataMutationVariables,
SettingsType,
SortOrder,
SourcePreferenceChangeInput,
StartDownloaderMutation,
@@ -2657,7 +2658,24 @@ export class RequestManager {
public useUpdateServerSettings(
options?: MutationHookOptions<UpdateServerSettingsMutation, UpdateServerSettingsMutationVariables>,
): AbortableApolloUseMutationResponse<UpdateServerSettingsMutation, UpdateServerSettingsMutationVariables> {
return this.doRequest(GQLMethod.USE_MUTATION, UPDATE_SERVER_SETTINGS, undefined, options);
const [mutate, result] = this.doRequest(GQLMethod.USE_MUTATION, UPDATE_SERVER_SETTINGS, undefined, options);
const wrappedMutate = async (mutateOptions: Parameters<typeof mutate>[0]) =>
mutate({
optimisticResponse: {
__typename: 'Mutation',
setSettings: {
__typename: 'SetSettingsPayload',
settings: {
__typename: 'SettingsType',
...(mutateOptions?.variables?.input.settings ?? {}),
} as SettingsType,
},
},
...mutateOptions,
});
return [wrappedMutate, result];
}
public useGetLastGlobalUpdateTimestamp(

View File

@@ -144,6 +144,14 @@ const typePolicies: StrictTypedTypePolicies = {
return existingWithAppendedIncoming;
},
},
settings: {
merge(existing, incoming) {
return {
...(existing ?? {}),
...(incoming ?? {}),
};
},
},
},
},
};