quivr/frontend/app/chat/components/ChatsList/hooks/useChatsList.ts
Mamadou DICKO 85eba3da70
feat: add onboarding step 3 (#1324)
* feat: add OnboardingContext

* feat: add Step3 boilerplate

* feat: activate step3

* feat: add <Step3/> content

* feat: add shouldStream guard on useStreamText
2023-10-04 16:26:56 +02:00

41 lines
1.1 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { CHATS_DATA_KEY } from "@/lib/api/chat/config";
import { useChatApi } from "@/lib/api/chat/useChatApi";
import { useChatsContext } from "@/lib/context/ChatsProvider/hooks/useChatsContext";
import { useToast } from "@/lib/hooks";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useChatsList = () => {
const { t } = useTranslation(["chat"]);
const { setAllChats } = useChatsContext();
const { publish } = useToast();
const { getChats } = useChatApi();
const fetchAllChats = async () => {
try {
const response = await getChats();
return response.reverse();
} catch (error) {
console.error(error);
publish({
variant: "danger",
text: t("errorFetching", { ns: "chat" }),
});
}
};
const { data: chats } = useQuery({
queryKey: [CHATS_DATA_KEY],
queryFn: fetchAllChats,
});
useEffect(() => {
setAllChats(chats ?? []);
}, [chats]);
};