2024-02-29 03:42:14 +03:00
|
|
|
"use client";
|
|
|
|
import { UUID } from "crypto";
|
|
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
|
|
|
|
|
|
import { LoaderIcon } from "@/lib/components/ui/LoaderIcon/LoaderIcon";
|
|
|
|
import { MessageInfoBox } from "@/lib/components/ui/MessageInfoBox/MessageInfoBox";
|
2024-03-01 22:30:46 +03:00
|
|
|
import QuivrButton from "@/lib/components/ui/QuivrButton/QuivrButton";
|
|
|
|
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
2024-02-29 03:42:14 +03:00
|
|
|
|
|
|
|
import styles from "./KnowledgeTab.module.scss";
|
|
|
|
import { KnowledgeTable } from "./KnowledgeTable/KnowledgeTable";
|
|
|
|
import { useAddedKnowledge } from "./hooks/useAddedKnowledge";
|
|
|
|
|
|
|
|
type KnowledgeTabProps = {
|
|
|
|
brainId: UUID;
|
|
|
|
hasEditRights: boolean;
|
|
|
|
};
|
|
|
|
export const KnowledgeTab = ({ brainId }: KnowledgeTabProps): JSX.Element => {
|
|
|
|
const { isPending, allKnowledge } = useAddedKnowledge({
|
|
|
|
brainId,
|
|
|
|
});
|
2024-03-01 22:30:46 +03:00
|
|
|
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
|
2024-02-29 03:42:14 +03:00
|
|
|
|
|
|
|
if (isPending) {
|
|
|
|
return <LoaderIcon size="big" color="accent" />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allKnowledge.length === 0) {
|
|
|
|
return (
|
|
|
|
<div className={styles.knowledge_tab_wrapper}>
|
2024-03-01 22:30:46 +03:00
|
|
|
<MessageInfoBox type="warning">
|
|
|
|
This brain is empty! You can add knowledge by clicking on
|
|
|
|
<QuivrButton
|
|
|
|
label="Add knowledge"
|
|
|
|
color="primary"
|
|
|
|
iconName="add"
|
|
|
|
onClick={() => setShouldDisplayFeedCard(true)}
|
|
|
|
/>
|
|
|
|
.
|
|
|
|
</MessageInfoBox>
|
2024-02-29 03:42:14 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.knowledge_tab_wrapper}>
|
|
|
|
<motion.div layout className="w-full flex flex-col gap-5">
|
|
|
|
<AnimatePresence mode="popLayout">
|
|
|
|
<KnowledgeTable knowledgeList={allKnowledge} />
|
|
|
|
</AnimatePresence>
|
|
|
|
</motion.div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|