2023-10-31 21:02:26 +03:00
|
|
|
import { UUID } from "crypto";
|
|
|
|
import { useParams } from "next/navigation";
|
|
|
|
|
2023-11-16 13:02:58 +03:00
|
|
|
import { useBrainFetcher } from "@/app/brains-management/[brainId]/components/BrainManagementTabs/hooks/useBrainFetcher";
|
|
|
|
|
2023-10-31 21:02:26 +03:00
|
|
|
import { useBrainContext } from "../context/BrainProvider/hooks/useBrainContext";
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
export const useUrlBrain = () => {
|
|
|
|
const { allBrains } = useBrainContext();
|
|
|
|
|
|
|
|
const params = useParams();
|
|
|
|
|
|
|
|
const brainId = params?.brainId as UUID | undefined;
|
|
|
|
const correspondingBrain = allBrains.find((brain) => brain.id === brainId);
|
2023-11-22 13:15:14 +03:00
|
|
|
|
2023-12-18 20:02:34 +03:00
|
|
|
const {
|
|
|
|
brain: brainDetails,
|
|
|
|
refetchBrain,
|
|
|
|
isLoading,
|
|
|
|
} = useBrainFetcher({
|
2023-11-16 13:02:58 +03:00
|
|
|
brainId: brainId,
|
|
|
|
});
|
2023-10-31 21:02:26 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
brain: correspondingBrain,
|
|
|
|
brainId,
|
2023-11-16 13:02:58 +03:00
|
|
|
brainDetails,
|
2023-11-22 13:15:14 +03:00
|
|
|
refetchBrain,
|
2023-12-18 20:02:34 +03:00
|
|
|
isLoading,
|
2023-10-31 21:02:26 +03:00
|
|
|
};
|
|
|
|
};
|