From c9db04d670b24c70f754c87e4eca9500c841f7fa Mon Sep 17 00:00:00 2001 From: mamadoudicko Date: Tue, 12 Sep 2023 16:58:41 +0200 Subject: [PATCH] feat: refecth notifications on Feed --- .../ActionsBar/hooks/useKnowledgeUploader.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/app/chat/[chatId]/components/ActionsBar/hooks/useKnowledgeUploader.ts b/frontend/app/chat/[chatId]/components/ActionsBar/hooks/useKnowledgeUploader.ts index 0c916cb87f31..ae541638e17e 100644 --- a/frontend/app/chat/[chatId]/components/ActionsBar/hooks/useKnowledgeUploader.ts +++ b/frontend/app/chat/[chatId]/components/ActionsBar/hooks/useKnowledgeUploader.ts @@ -7,7 +7,9 @@ import { useTranslation } from "react-i18next"; import { useChatApi } from "@/lib/api/chat/useChatApi"; import { useCrawlApi } from "@/lib/api/crawl/useCrawlApi"; +import { useNotificationApi } from "@/lib/api/notification/useNotificationApi"; import { useUploadApi } from "@/lib/api/upload/useUploadApi"; +import { useChatContext } from "@/lib/context"; import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; import { useToast } from "@/lib/hooks"; @@ -26,11 +28,13 @@ export const useKnowledgeUploader = ({ const { t } = useTranslation(["upload"]); const { crawlWebsiteUrl } = useCrawlApi(); const { createChat } = useChatApi(); + const { currentBrainId } = useBrainContext(); + const { setNotifications } = useChatContext(); + const { getChatNotifications } = useNotificationApi(); const params = useParams(); const chatId = params?.chatId as UUID | undefined; - const { currentBrainId } = useBrainContext(); const addContent = (content: FeedItemType) => { setContents((prevContents) => [...prevContents, content]); }; @@ -38,6 +42,11 @@ export const useKnowledgeUploader = ({ setContents((prevContents) => prevContents.filter((_, i) => i !== index)); }; + const fetchNotifications = async (currentChatId: UUID): Promise => { + const fetchedNotifications = await getChatNotifications(currentChatId); + setNotifications(fetchedNotifications); + }; + const crawlWebsiteHandler = useCallback( async (url: string, brainId: UUID, chat_id: UUID) => { // Configure parameters @@ -56,6 +65,7 @@ export const useKnowledgeUploader = ({ config, chat_id, }); + await fetchNotifications(chat_id); } catch (error: unknown) { publish({ variant: "danger", @@ -81,6 +91,7 @@ export const useKnowledgeUploader = ({ formData, chat_id, }); + await fetchNotifications(chat_id); } catch (e: unknown) { if (axios.isAxiosError(e) && e.response?.status === 403) { publish({