add active search space chats atom with query

This commit is contained in:
thierryverse 2025-11-12 12:03:06 +02:00
parent 9567a3ce23
commit 93f6056a91
10 changed files with 81 additions and 29 deletions

View file

@ -0,0 +1,23 @@
import { atomWithQuery } from "jotai-tanstack-query";
import { fetchChatsBySearchSpace } from "@/lib/apis/chat-apis";
import { activeSearchSpaceIdAtom } from "../seach-space/active-seach-space.atom";
export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
const searchSpaceId = get(activeSearchSpaceIdAtom);
const authToken = localStorage.getItem("surfsense_bearer_token");
return {
queryKey: ["chatsBySearchSpace", searchSpaceId],
enabled: !!searchSpaceId && !!authToken,
queryFn: async () => {
if (!authToken) {
throw new Error("No authentication token found");
}
if (!searchSpaceId) {
throw new Error("No search space id found");
}
return fetchChatsBySearchSpace(searchSpaceId, authToken);
},
};
});