update chat api service

This commit is contained in:
thierryverse 2025-11-15 03:28:33 +02:00
parent b35a5aa589
commit 776660f5e3
5 changed files with 137 additions and 122 deletions

View file

@ -2,6 +2,7 @@ import { atomWithMutation } from "jotai-tanstack-query";
import { toast } from "sonner";
import type { Chat } from "@/app/dashboard/[search_space_id]/chats/chats-client";
import { deleteChat } from "@/lib/apis/chats.api";
import { chatApiService } from "@/lib/apis/chats-api.service";
import { cacheKeys } from "@/lib/query-client/cache-keys";
import { queryClient } from "@/lib/query-client/client";
import { activeSearchSpaceIdAtom } from "../seach-spaces/seach-space-queries.atom";
@ -14,14 +15,7 @@ export const deleteChatMutationAtom = atomWithMutation((get) => {
mutationKey: cacheKeys.activeSearchSpace.chats(searchSpaceId ?? ""),
enabled: !!searchSpaceId && !!authToken,
mutationFn: async (chatId: number) => {
if (!authToken) {
throw new Error("No authentication token found");
}
if (!searchSpaceId) {
throw new Error("No search space id found");
}
return deleteChat(chatId, authToken);
return chatApiService.deleteChat({ id: chatId });
},
onSuccess: (_, chatId) => {

View file

@ -4,6 +4,7 @@ import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/seach-space-queries.atom";
import { fetchChatDetails, fetchChatsBySearchSpace } from "@/lib/apis/chats.api";
import { chatApiService } from "@/lib/apis/chats-api.service";
import { getPodcastByChatId } from "@/lib/apis/podcasts.api";
import { cacheKeys } from "@/lib/query-client/cache-keys";
@ -32,7 +33,7 @@ export const activeChatAtom = atomWithQuery<ActiveChatState>((get) => {
const [podcast, chatDetails] = await Promise.all([
getPodcastByChatId(activeChatId, authToken),
fetchChatDetails(activeChatId, authToken),
chatApiService.getChatDetails({ id: Number(activeChatId) }),
]);
return { chatId: activeChatId, chatDetails, podcast };
@ -48,14 +49,7 @@ export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
queryKey: cacheKeys.activeSearchSpace.chats(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);
return chatApiService.getChatsBySearchSpace({ search_space_id: Number(searchSpaceId) });
},
};
});