mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-18 08:02:03 +03:00
b64fc044c4
* 🚧 🌐 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
33 lines
959 B
TypeScript
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 };
|
|
};
|