mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-19 00:22:14 +03:00
9464707d40
* feat: add chat_id to upload and crawl payload * feat(chat): return chat_history_with_notifications * feat: explicit notification status on create * feat: handle notifications in frontend * feat: delete chat notifications on chat delete request
34 lines
923 B
TypeScript
34 lines
923 B
TypeScript
import { useParams } from "next/navigation";
|
|
import { useEffect } from "react";
|
|
|
|
import { useChatApi } from "@/lib/api/chat/useChatApi";
|
|
import { useChatContext } from "@/lib/context";
|
|
|
|
import { getMessagesFromChatHistory } from "../utils/getMessagesFromChatHistory";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useSelectedChatPage = () => {
|
|
const { setHistory } = useChatContext();
|
|
const { getHistory } = useChatApi();
|
|
|
|
const params = useParams();
|
|
const chatId = params?.chatId as string | undefined;
|
|
|
|
useEffect(() => {
|
|
const fetchHistory = async () => {
|
|
if (chatId === undefined) {
|
|
setHistory([]);
|
|
|
|
return;
|
|
}
|
|
|
|
const chatHistory = await getHistory(chatId);
|
|
|
|
if (chatHistory.length > 0) {
|
|
setHistory(getMessagesFromChatHistory(chatHistory));
|
|
}
|
|
};
|
|
void fetchHistory();
|
|
}, [chatId, setHistory]);
|
|
};
|