mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
feat: add snapshots cache key and query atom
This commit is contained in:
parent
47b7befc55
commit
e62e4faaa5
2 changed files with 25 additions and 0 deletions
22
surfsense_web/atoms/snapshots/snapshots-query.atoms.ts
Normal file
22
surfsense_web/atoms/snapshots/snapshots-query.atoms.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { atomWithQuery } from "jotai-tanstack-query";
|
||||||
|
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
|
||||||
|
import { chatThreadsApiService } from "@/lib/apis/chat-threads-api.service";
|
||||||
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
|
|
||||||
|
export const searchSpaceSnapshotsAtom = atomWithQuery((get) => {
|
||||||
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
|
||||||
|
return {
|
||||||
|
queryKey: cacheKeys.snapshots.bySearchSpace(Number(searchSpaceId) || 0),
|
||||||
|
enabled: !!searchSpaceId,
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!searchSpaceId) {
|
||||||
|
return { snapshots: [] };
|
||||||
|
}
|
||||||
|
return chatThreadsApiService.listSearchSpaceSnapshots({
|
||||||
|
search_space_id: Number(searchSpaceId),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
@ -82,4 +82,7 @@ export const cacheKeys = {
|
||||||
publicChat: {
|
publicChat: {
|
||||||
byToken: (shareToken: string) => ["public-chat", shareToken] as const,
|
byToken: (shareToken: string) => ["public-chat", shareToken] as const,
|
||||||
},
|
},
|
||||||
|
snapshots: {
|
||||||
|
bySearchSpace: (searchSpaceId: number) => ["snapshots", "search-space", searchSpaceId] as const,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue