Skip to content

Commit

Permalink
feat: refecth notifications on Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko committed Sep 12, 2023
1 parent 7b159d9 commit c9db04d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -26,18 +28,25 @@ 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]);
};
const removeContent = (index: number) => {
setContents((prevContents) => prevContents.filter((_, i) => i !== index));
};

const fetchNotifications = async (currentChatId: UUID): Promise<void> => {
const fetchedNotifications = await getChatNotifications(currentChatId);
setNotifications(fetchedNotifications);
};

const crawlWebsiteHandler = useCallback(
async (url: string, brainId: UUID, chat_id: UUID) => {
// Configure parameters
Expand All @@ -56,6 +65,7 @@ export const useKnowledgeUploader = ({
config,
chat_id,
});
await fetchNotifications(chat_id);
} catch (error: unknown) {
publish({
variant: "danger",
Expand All @@ -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({
Expand Down

0 comments on commit c9db04d

Please sign in to comment.