2023-05-22 20:54:07 +03:00
|
|
|
"use client";
|
2023-05-27 17:42:48 +03:00
|
|
|
import { AnimatePresence, motion } from "framer-motion";
|
2023-05-22 21:24:18 +03:00
|
|
|
import Link from "next/link";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
|
|
|
import Button from "@/lib/components/ui/Button";
|
|
|
|
import Spinner from "@/lib/components/ui/Spinner";
|
2023-07-19 14:51:53 +03:00
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
2023-06-20 17:17:13 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2023-07-13 19:05:08 +03:00
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
2023-07-19 14:51:53 +03:00
|
|
|
|
2023-05-26 14:56:29 +03:00
|
|
|
import DocumentItem from "./DocumentItem";
|
2023-07-06 20:01:23 +03:00
|
|
|
import { useExplore } from "./hooks/useExplore";
|
2023-05-24 23:21:22 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const ExplorePage = (): JSX.Element => {
|
2023-05-26 14:56:29 +03:00
|
|
|
const { session } = useSupabase();
|
2023-07-06 20:01:23 +03:00
|
|
|
const { documents, setDocuments, isPending } = useExplore();
|
2023-07-19 14:51:53 +03:00
|
|
|
const { currentBrain } = useBrainContext();
|
2023-05-24 23:21:22 +03:00
|
|
|
if (session === null) {
|
2023-07-13 19:05:08 +03:00
|
|
|
redirectToLogin();
|
2023-05-24 23:21:22 +03:00
|
|
|
}
|
2023-07-19 14:51:53 +03:00
|
|
|
if (currentBrain === undefined) {
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col items-center justify-center mt-10 gap-1">
|
|
|
|
<p className="text-center">
|
|
|
|
{"You need to select a brain first. 🧠💡🥲"}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-05-22 20:54:07 +03:00
|
|
|
return (
|
2023-05-23 11:06:58 +03:00
|
|
|
<main>
|
2023-06-11 11:44:23 +03:00
|
|
|
<section className="w-full outline-none pt-10 flex flex-col gap-5 items-center justify-center p-6">
|
2023-05-27 17:42:48 +03:00
|
|
|
<div className="flex flex-col items-center justify-center">
|
2023-05-26 11:57:29 +03:00
|
|
|
<h1 className="text-3xl font-bold text-center">
|
2023-07-19 14:51:53 +03:00
|
|
|
Explore uploaded data in {currentBrain.name}
|
2023-05-26 11:57:29 +03:00
|
|
|
</h1>
|
|
|
|
<h2 className="opacity-50">
|
|
|
|
View or delete stored data used by your brain
|
|
|
|
</h2>
|
2023-05-23 08:34:53 +03:00
|
|
|
</div>
|
2023-05-23 11:06:58 +03:00
|
|
|
{isPending ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
2023-05-27 17:42:48 +03:00
|
|
|
<motion.div layout className="w-full max-w-xl flex flex-col gap-5">
|
2023-05-23 11:06:58 +03:00
|
|
|
{documents.length !== 0 ? (
|
2023-05-27 17:42:48 +03:00
|
|
|
<AnimatePresence mode="popLayout">
|
2023-05-23 11:06:58 +03:00
|
|
|
{documents.map((document) => (
|
|
|
|
<DocumentItem
|
|
|
|
key={document.name}
|
|
|
|
document={document}
|
|
|
|
setDocuments={setDocuments}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</AnimatePresence>
|
|
|
|
) : (
|
|
|
|
<div className="flex flex-col items-center justify-center mt-10 gap-1">
|
|
|
|
<p className="text-center">Oh No, Your Brain is empty.</p>
|
|
|
|
<Link href="/upload">
|
2023-05-25 11:10:35 +03:00
|
|
|
<Button>Upload</Button>
|
2023-05-23 11:06:58 +03:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-05-27 17:42:48 +03:00
|
|
|
</motion.div>
|
2023-05-23 11:06:58 +03:00
|
|
|
)}
|
|
|
|
</section>
|
|
|
|
</main>
|
2023-05-22 20:54:07 +03:00
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ExplorePage;
|