quivr/frontend/app/chat/layout.tsx
Stan Girard d0b8b797f6
feat(search): new way to interact with Quivr (#2026)
Co-authored-by: Zewed <dewez.antoine2@gmail.com>
Co-authored-by: Antoine Dewez <44063631+Zewed@users.noreply.github.com>
2024-01-19 20:34:30 -08:00

43 lines
1.1 KiB
TypeScript

"use client";
import { usePathname, useRouter } from "next/navigation";
import { ReactNode, useEffect, useState } from "react";
import { KnowledgeToFeedProvider } from "@/lib/context";
import { useSupabase } from "@/lib/context/SupabaseProvider";
import { redirectToLogin } from "@/lib/router/redirectToLogin";
interface LayoutProps {
children?: ReactNode;
}
const Layout = ({ children }: LayoutProps): JSX.Element => {
const { session } = useSupabase();
const pathname = usePathname();
const router = useRouter();
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
if (session === null) {
redirectToLogin();
} else if (pathname === '/chat') {
router.push('/search');
} else {
setIsLoading(false);
}
}, [session, pathname, router]);
if (isLoading) {
return <></>
}
return (
<KnowledgeToFeedProvider>
<div className="relative h-full w-full flex justify-stretch items-stretch overflow-auto">
{children}
</div>
</KnowledgeToFeedProvider>
);
};
export default Layout;