SurfSense/surfsense_web/atoms/search-spaces/search-space-mutation.atoms.ts
DESKTOP-RTLN3BA\$punk c768730b8c feat: fixed issues of note management
Issues Fixed

- Missing pagination fields in API response schemas (page, page_size, has_more)
- NOTE enum missing from frontend Zod schema
- Missing fields in DocumentRead response construction (content_hash, updated_at)
- BlockNote slash menu clipped by overflow-hidden CSS
- Sidebar click conflicts - hidden action buttons intercepting clicks
- Rewrote All Notes sidebar - replaced fragile custom portal with shadcn Sheet
- Missing translation keys for new UI strings
- Missing NOTE retrieval logic in researcher agent
- Added search to All Notes sidebar
- Removed frontend logging - was causing toasters on every page refresh
- Added backend logging to document reindex Celery task
2025-12-17 00:09:43 -08:00

75 lines
2.3 KiB
TypeScript

import { atomWithMutation } from "jotai-tanstack-query";
import { toast } from "sonner";
import type {
CreateSearchSpaceRequest,
DeleteSearchSpaceRequest,
UpdateSearchSpaceRequest,
} from "@/contracts/types/search-space.types";
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
import { cacheKeys } from "@/lib/query-client/cache-keys";
import { queryClient } from "@/lib/query-client/client";
import { activeSearchSpaceIdAtom } from "./search-space-query.atoms";
export const createSearchSpaceMutationAtom = atomWithMutation(() => {
return {
mutationKey: ["create-search-space"],
mutationFn: async (request: CreateSearchSpaceRequest) => {
return searchSpacesApiService.createSearchSpace(request);
},
onSuccess: () => {
toast.success("Search space created successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.searchSpaces.all,
});
},
};
});
export const updateSearchSpaceMutationAtom = atomWithMutation((get) => {
const activeSearchSpaceId = get(activeSearchSpaceIdAtom);
return {
mutationKey: ["update-search-space", activeSearchSpaceId],
enabled: !!activeSearchSpaceId,
mutationFn: async (request: UpdateSearchSpaceRequest) => {
return searchSpacesApiService.updateSearchSpace(request);
},
onSuccess: (_, request: UpdateSearchSpaceRequest) => {
toast.success("Search space updated successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.searchSpaces.all,
});
if (request.id) {
queryClient.invalidateQueries({
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
});
}
},
};
});
export const deleteSearchSpaceMutationAtom = atomWithMutation((get) => {
const activeSearchSpaceId = get(activeSearchSpaceIdAtom);
return {
mutationKey: ["delete-search-space", activeSearchSpaceId],
enabled: !!activeSearchSpaceId,
mutationFn: async (request: DeleteSearchSpaceRequest) => {
return searchSpacesApiService.deleteSearchSpace(request);
},
onSuccess: (_, request: DeleteSearchSpaceRequest) => {
toast.success("Search space deleted successfully");
queryClient.invalidateQueries({
queryKey: cacheKeys.searchSpaces.all,
});
if (request.id) {
queryClient.removeQueries({
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
});
}
},
};
});