mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-21 10:21:54 +03:00
7480e89fa9
Issue: https://github.com/StanGirard/quivr/issues/1902 Demo: https://github.com/StanGirard/quivr/assets/63923024/33170c91-3bdc-442a-918a-5013b423f8e5
30 lines
811 B
TypeScript
30 lines
811 B
TypeScript
import { useState } from "react";
|
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useBrainsTabs = () => {
|
|
const [searchQuery, setSearchQuery] = useState("");
|
|
const { allBrains, isFetchingBrains } = useBrainContext();
|
|
|
|
const brains = allBrains.filter((brain) => {
|
|
const query = searchQuery.toLowerCase();
|
|
const name = brain.name.toLowerCase();
|
|
|
|
return name.includes(query);
|
|
});
|
|
|
|
const privateBrains = brains.filter((brain) => brain.status === "private");
|
|
|
|
const publicBrains = brains.filter((brain) => brain.status === "public");
|
|
|
|
return {
|
|
searchQuery,
|
|
setSearchQuery,
|
|
brains,
|
|
privateBrains,
|
|
publicBrains,
|
|
isFetchingBrains,
|
|
};
|
|
};
|