mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 01:21:48 +03:00
fix(frontend): set chat messages only if needed (#2040)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
563ee470c8
commit
fe42c9a82d
@ -7,20 +7,17 @@ import { useNotificationApi } from "@/lib/api/notification/useNotificationApi";
|
||||
import { useChatContext } from "@/lib/context";
|
||||
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
||||
|
||||
import { useChatInput } from "../components/ActionsBar/components/ChatInput/hooks/useChatInput";
|
||||
import { getChatNotificationsQueryKey } from "../utils/getChatNotificationsQueryKey";
|
||||
import { getMessagesFromChatItems } from "../utils/getMessagesFromChatItems";
|
||||
import { getNotificationsFromChatItems } from "../utils/getNotificationsFromChatItems";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export const useChatNotificationsSync = () => {
|
||||
const { message } = useChatInput()
|
||||
const { setMessages, setNotifications, notifications } = useChatContext();
|
||||
const { getChatItems } = useChatApi();
|
||||
const { getChatNotifications } = useNotificationApi();
|
||||
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
|
||||
const params = useParams();
|
||||
|
||||
const chatId = params?.chatId as string | undefined;
|
||||
|
||||
const chatNotificationsQueryKey = getChatNotificationsQueryKey(chatId ?? "");
|
||||
@ -66,10 +63,13 @@ export const useChatNotificationsSync = () => {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
const chatItems = await getChatItems(chatId);
|
||||
setMessages(getMessagesFromChatItems(chatItems));
|
||||
const chatItems = await getChatItems(chatId);
|
||||
const messagesFromChatItems = getMessagesFromChatItems(chatItems);
|
||||
if (
|
||||
messagesFromChatItems.length > 1 ||
|
||||
(messagesFromChatItems[0] && messagesFromChatItems[0].assistant !== "")
|
||||
) {
|
||||
setMessages(messagesFromChatItems);
|
||||
setNotifications(getNotificationsFromChatItems(chatItems));
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user