mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-19 00:22:14 +03:00
10af0c949a
* feat: rename ChatMessages to MessagesDialog * feat: rename history to messages * feat: add notifications to ChatContext * feat: add getNotificationsFromChatHistory * feat: add getMergedChatHistoryWithReducedNotifications * refactor: update useActionBar * refactor: update <ChatMessage />-n * feat: update crawler and endpoint notifications content * feat: display notifications * test: update <MessageDialog /> tests * feat: rename ChatMessage to QADisplay * feat: rename ChatHistory to ChatMessage * feat(upload): throw error when file missing * feat: rename getMergedChatHistoryWithReducedNotifications to getMergedChatMessagesWithReducedNotifications * feat: change history wording to message * feat: move getFileIcon to lib * refactor(NotificationDisplayer): move types to types.ts * chore: improve ux * feat: rename MessagesDialog to ChatDialogue
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { useParams } from "next/navigation";
|
|
import { useEffect } from "react";
|
|
|
|
import { useChatApi } from "@/lib/api/chat/useChatApi";
|
|
import { useChatContext } from "@/lib/context";
|
|
|
|
import { getMessagesFromChatItems } from "../utils/getMessagesFromChatItems";
|
|
import { getNotificationsFromChatItems } from "../utils/getNotificationsFromChatItems";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useSelectedChatPage = () => {
|
|
const { setMessages, setNotifications } = useChatContext();
|
|
const { getChatItems } = useChatApi();
|
|
|
|
const params = useParams();
|
|
const chatId = params?.chatId as string | undefined;
|
|
|
|
useEffect(() => {
|
|
const fetchHistory = async () => {
|
|
if (chatId === undefined) {
|
|
setMessages([]);
|
|
setNotifications([]);
|
|
|
|
return;
|
|
}
|
|
|
|
const chatItems = await getChatItems(chatId);
|
|
|
|
setMessages(getMessagesFromChatItems(chatItems));
|
|
setNotifications(getNotificationsFromChatItems(chatItems));
|
|
};
|
|
void fetchHistory();
|
|
}, [chatId, setMessages]);
|
|
};
|