mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
feat: add deleteLLMConfigMutationAtom and fix cache key usage in all LLM config mutations
This commit is contained in:
parent
737169248e
commit
1aa10db910
2 changed files with 44 additions and 2 deletions
|
|
@ -1,7 +1,12 @@
|
|||
import { atomWithMutation } from "jotai-tanstack-query";
|
||||
import { toast } from "sonner";
|
||||
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/seach-space-queries.atom";
|
||||
import type { CreateLLMConfigRequest, UpdateLLMConfigRequest } from "@/contracts/types/llm-config.types";
|
||||
import type {
|
||||
CreateLLMConfigRequest,
|
||||
UpdateLLMConfigRequest,
|
||||
DeleteLLMConfigRequest,
|
||||
GetLLMConfigsResponse,
|
||||
} from "@/contracts/types/llm-config.types";
|
||||
import { llmConfigApiService } from "@/lib/apis/llm-config-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -52,3 +57,37 @@ export const updateLLMConfigMutationAtom = atomWithMutation((get) => {
|
|||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const deleteLLMConfigMutationAtom = atomWithMutation((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
const authToken = localStorage.getItem("surfsense_bearer_token");
|
||||
|
||||
return {
|
||||
mutationKey: cacheKeys.llmConfigs.all(searchSpaceId!),
|
||||
enabled: !!searchSpaceId && !!authToken,
|
||||
mutationFn: async (request: DeleteLLMConfigRequest) => {
|
||||
return llmConfigApiService.deleteLLMConfig(request);
|
||||
},
|
||||
|
||||
onSuccess: (_, request: DeleteLLMConfigRequest) => {
|
||||
toast.success("LLM configuration deleted successfully");
|
||||
queryClient.setQueryData(
|
||||
cacheKeys.llmConfigs.all(searchSpaceId!),
|
||||
(oldData: GetLLMConfigsResponse | undefined) => {
|
||||
if (!oldData) return oldData;
|
||||
return {
|
||||
...oldData,
|
||||
items: oldData.items.filter((config) => config.id !== request.id),
|
||||
total: oldData.total - 1,
|
||||
};
|
||||
}
|
||||
);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.llmConfigs.byId(String(request.id)),
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.llmConfigs.global(),
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue