quivr/frontend/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext.tsx
Zineb El Bachiri b64fc044c4
feat: knowledge tab add button (#1277)
* 🚧 🌐 knowledge traductions

* 🔥 replace useKnowledge hook

*  AddKnowledge in knowledge  tab

* 🚧 extract feedBrain in chat hook

* ♻️ use feedBrain method as a prop in KnowledgeToFeedInput

*  custom feedBrain for chat and brain management

*  add loader when deleting

* 🚑 remove chat after auto creation for each feed action

* 🚚 rename KnowledgeProvider into KnowledgeToFeedProvider
2023-09-28 15:39:30 +02:00

33 lines
959 B
TypeScript

import { useContext } from "react";
import { FeedItemType } from "@/app/chat/[chatId]/components/ActionsBar/types";
import { KnowledgeToFeedContext } from "../knowledgeToFeed-provider";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useKnowledgeToFeedContext = () => {
const context = useContext(KnowledgeToFeedContext);
const addKnowledgeToFeed = (knowledge: FeedItemType) => {
context?.setKnowledgeToFeed((prevKnowledge) => [
...prevKnowledge,
knowledge,
]);
};
const removeKnowledgeToFeed = (index: number) => {
context?.setKnowledgeToFeed((prevKnowledge) => {
const newKnowledge = [...prevKnowledge];
newKnowledge.splice(index, 1);
return newKnowledge;
});
};
if (context === undefined) {
throw new Error("useKnowledge must be used inside KnowledgeToFeedProvider");
}
return { ...context, addKnowledgeToFeed, removeKnowledgeToFeed };
};