-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
31 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...agement/[brainId]/components/BrainManagementTabs/components/KnowledgeTab/AddKnowledge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { AiOutlineLoading3Quarters } from "react-icons/ai"; | ||
|
||
import { KnowledgeToFeedInput } from "@/lib/components/KnowledgeToFeedInput"; | ||
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; | ||
|
||
import { useKnowledge } from "./hooks/useKnowledge"; | ||
|
||
export const AddKnowledge = (): JSX.Element => { | ||
const { t } = useTranslation(["knowledge"]); | ||
|
||
const [shouldDiplayModal, setShouldDisplayModal] = useState(false); | ||
const [hasPendingRequests, setHasPendingRequests] = useState(false); | ||
const { currentBrain } = useBrainContext(); | ||
const { invalidateKnowledgeDataKey } = useKnowledge({ | ||
brainId: currentBrain?.id, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!hasPendingRequests) { | ||
invalidateKnowledgeDataKey(); | ||
} | ||
}, [hasPendingRequests, invalidateKnowledgeDataKey]); | ||
|
||
return ( | ||
<> | ||
<button | ||
className="flex flex-1 items-center justify-center rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-2 md:p-6" | ||
onClick={() => setShouldDisplayModal(true)} | ||
> | ||
<div className="flex flex-lin items-center"> | ||
<span className="text-2xl md:text-3xl">+</span> | ||
</div> | ||
</button> | ||
{hasPendingRequests && ( | ||
<div className="flex mt-1 flex-col md:flex-row shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-2 md:p-6 pl-6"> | ||
<AiOutlineLoading3Quarters className="animate-spin text-2xl md:text-3xl self-center" /> | ||
</div> | ||
)} | ||
{shouldDiplayModal && ( | ||
<KnowledgeToFeedInput | ||
closeFeedInput={() => setShouldDisplayModal(false)} | ||
dispatchHasPendingRequests={() => setHasPendingRequests(true)} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters