mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
feat(search-spaces): add searchSpacesAtom query atom for fetching search spaces list
This commit is contained in:
parent
edfe2aa87e
commit
58a14f422d
1 changed files with 26 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import { atom } from "jotai";
|
||||
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";
|
||||
|
||||
// Atom to store current query params for search spaces
|
||||
export const searchSpacesQueryParamsAtom = atom<GetSearchSpacesRequest["queryParams"]>({
|
||||
page: 0,
|
||||
page_size: 10,
|
||||
});
|
||||
|
||||
// Query atom to fetch search spaces with query params
|
||||
export const searchSpacesAtom = atomWithQuery((get) => {
|
||||
const queryParams = get(searchSpacesQueryParamsAtom);
|
||||
|
||||
return {
|
||||
queryKey: cacheKeys.searchSpaces.withQueryParams(queryParams),
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
queryFn: async () => {
|
||||
return searchSpacesApiService.getSearchSpaces({
|
||||
queryParams,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue