-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
1 parent
f7c867b
commit 3e11c67
Showing
12 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
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
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
26 changes: 26 additions & 0 deletions
26
frontend/app/brains-management/library/components/PublicBrainItem.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,26 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import { MdAdd } from "react-icons/md"; | ||
|
||
import Button from "@/lib/components/ui/Button"; | ||
import { Brain } from "@/lib/context/BrainProvider/types"; | ||
|
||
type PublicBrainItemProps = { | ||
brain: Brain; | ||
}; | ||
|
||
export const PublicBrainItem = ({ | ||
brain, | ||
}: PublicBrainItemProps): JSX.Element => { | ||
const { t } = useTranslation("brain"); | ||
|
||
return ( | ||
<div className="flex justify-center items-center flex-col w-full h-full shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl overflow-hidden bg-white dark:bg-black border border-black/10 dark:border-white/25 md:p-5"> | ||
<p className="font-bold mb-5 text-xl">{brain.name}</p> | ||
<p className="line-clamp-2 text-center px-5">{brain.description ?? ""}</p> | ||
<Button className="bg-purple-600 text-white p-0 px-3 rounded-xl border-0 w-content mt-3"> | ||
{t("public_brain_subscribe_button_label")} | ||
<MdAdd className="text-md" /> | ||
</Button> | ||
</div> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
frontend/app/brains-management/library/hooks/useBrainsLibrary.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,43 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import { PUBLIC_BRAINS_KEY } from "@/lib/api/brain/config"; | ||
import { useBrainApi } from "@/lib/api/brain/useBrainApi"; | ||
import { Brain } from "@/lib/context/BrainProvider/types"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const useBrainsLibrary = () => { | ||
const [searchBarText, setSearchBarText] = useState(""); | ||
const { getPublicBrains } = useBrainApi(); | ||
const { data: publicBrains = [] } = useQuery({ | ||
queryKey: [PUBLIC_BRAINS_KEY], | ||
queryFn: getPublicBrains, | ||
}); | ||
|
||
const [displayingPublicBrains, setDisplayingPublicBrains] = useState<Brain[]>( | ||
[] | ||
); | ||
|
||
useEffect(() => { | ||
setDisplayingPublicBrains(publicBrains); | ||
}, [publicBrains]); | ||
|
||
useEffect(() => { | ||
if (searchBarText === "") { | ||
setDisplayingPublicBrains(publicBrains); | ||
|
||
return; | ||
} | ||
setDisplayingPublicBrains( | ||
publicBrains.filter((brain) => | ||
brain.name.toLowerCase().includes(searchBarText.toLowerCase()) | ||
) | ||
); | ||
}, [publicBrains, searchBarText]); | ||
|
||
return { | ||
displayingPublicBrains, | ||
searchBarText, | ||
setSearchBarText, | ||
}; | ||
}; |
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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const brainDataKey = "quivr-brains"; | ||
const BRAIN_DATA_KEY = "quivr-brains"; | ||
|
||
export const getBrainDataKey = (brainId: string): string => | ||
`${brainDataKey}-${brainId}`; | ||
`${BRAIN_DATA_KEY}-${brainId}`; | ||
|
||
export const getBrainKnowledgeDataKey = (brainId: string): string => | ||
`${brainDataKey}-${brainId}-knowledge`; | ||
`${BRAIN_DATA_KEY}-${brainId}-knowledge`; | ||
|
||
export const PUBLIC_BRAINS_KEY = "quivr-public-brains"; |
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
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
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
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
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
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