mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-19 00:22:14 +03:00
9be4a57979
Issues: https://github.com/StanGirard/quivr/issues/1497 https://github.com/StanGirard/quivr/issues/1495 https://github.com/StanGirard/quivr/issues/1506 1. feat(chatInput): increase upload button size 2. feat(brains-library): add Spinner on loading 3. feat: improve logout ux ![Screenshot 2023-10-30 at 11 48 58](https://github.com/StanGirard/quivr/assets/63923024/fb8e0848-b349-4fbd-a7a5-ff43a73ae364) https://github.com/StanGirard/quivr/assets/63923024/cbd7cd42-e58a-49fb-9867-97f19dde9270 https://github.com/StanGirard/quivr/assets/63923024/a69b6b28-1c19-43e7-a02b-1df215a34a2e
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
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 { PublicBrain } 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 = [], isLoading } = useQuery({
|
|
queryKey: [PUBLIC_BRAINS_KEY],
|
|
queryFn: getPublicBrains,
|
|
});
|
|
|
|
const [displayingPublicBrains, setDisplayingPublicBrains] = useState<
|
|
PublicBrain[]
|
|
>([]);
|
|
|
|
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,
|
|
isLoading,
|
|
};
|
|
};
|