mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-08 22:22:17 +02:00
feat: zero_publication on startup and init migration from search space to workspace.
This commit is contained in:
parent
576821fb40
commit
7562bc78ee
17 changed files with 0 additions and 0 deletions
98
surfsense_web/atoms/workspaces/workspace-mutation.atoms.ts
Normal file
98
surfsense_web/atoms/workspaces/workspace-mutation.atoms.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import { atomWithMutation } from "jotai-tanstack-query";
|
||||
import { toast } from "sonner";
|
||||
import type {
|
||||
CreateSearchSpaceRequest,
|
||||
DeleteSearchSpaceRequest,
|
||||
UpdateSearchSpaceApiAccessRequest,
|
||||
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 updateSearchSpaceApiAccessMutationAtom = atomWithMutation((get) => {
|
||||
const activeSearchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
|
||||
return {
|
||||
mutationKey: ["update-search-space-api-access", activeSearchSpaceId],
|
||||
enabled: !!activeSearchSpaceId,
|
||||
mutationFn: async (request: UpdateSearchSpaceApiAccessRequest) => {
|
||||
return searchSpacesApiService.updateSearchSpaceApiAccess(request);
|
||||
},
|
||||
|
||||
onSuccess: (_, request: UpdateSearchSpaceApiAccessRequest) => {
|
||||
toast.success("API access updated successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.all,
|
||||
});
|
||||
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)),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
27
surfsense_web/atoms/workspaces/workspace-query.atoms.ts
Normal file
27
surfsense_web/atoms/workspaces/workspace-query.atoms.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { atom } from "jotai";
|
||||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import type { GetSearchSpacesRequest } from "@/contracts/types/search-space.types";
|
||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
|
||||
export const activeSearchSpaceIdAtom = atom<string | null>(null);
|
||||
|
||||
export const searchSpacesQueryParamsAtom = atom<GetSearchSpacesRequest["queryParams"]>({
|
||||
skip: 0,
|
||||
limit: 10,
|
||||
owned_only: false,
|
||||
});
|
||||
|
||||
export const searchSpacesAtom = atomWithQuery((get) => {
|
||||
const queryParams = get(searchSpacesQueryParamsAtom);
|
||||
|
||||
return {
|
||||
queryKey: cacheKeys.searchSpaces.withQueryParams(queryParams),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
queryFn: async () => {
|
||||
return searchSpacesApiService.getSearchSpaces({
|
||||
queryParams,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue