2023-05-22 20:54:07 +03:00
|
|
|
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
import axios from "axios";
|
|
|
|
import DocumentItem from "./DocumentItem";
|
|
|
|
import { Document } from "./types";
|
2023-05-22 21:24:18 +03:00
|
|
|
import Button from "../components/ui/Button";
|
|
|
|
import Link from "next/link";
|
2023-05-21 02:20:55 +03:00
|
|
|
|
|
|
|
export default function ExplorePage() {
|
2023-05-22 20:54:07 +03:00
|
|
|
const [documents, setDocuments] = useState<Document[]>([]);
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-05-22 20:54:07 +03:00
|
|
|
useEffect(() => {
|
|
|
|
fetchDocuments();
|
|
|
|
}, []);
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-05-22 20:54:07 +03:00
|
|
|
const fetchDocuments = async () => {
|
|
|
|
try {
|
|
|
|
console.log(
|
|
|
|
`Fetching documents from ${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`
|
|
|
|
);
|
|
|
|
const response = await axios.get<{ documents: Document[] }>(
|
|
|
|
`${process.env.NEXT_PUBLIC_BACKEND_URL}/explore`
|
|
|
|
);
|
|
|
|
setDocuments(response.data.documents);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching documents", error);
|
|
|
|
setDocuments([]);
|
|
|
|
}
|
|
|
|
};
|
2023-05-21 02:20:55 +03:00
|
|
|
|
2023-05-22 20:54:07 +03:00
|
|
|
return (
|
|
|
|
<div className="pt-20 flex flex-col items-center justify-center p-6">
|
2023-05-22 21:05:52 +03:00
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
<h1 className="text-3xl font-bold text-center">Explore Your Brain</h1>
|
|
|
|
<h2 className="opacity-50">View what’s in your second brain</h2>
|
|
|
|
</div>
|
2023-05-22 20:54:07 +03:00
|
|
|
<div className="w-full max-w-xl flex flex-col gap-5">
|
2023-05-22 21:24:18 +03:00
|
|
|
{documents.length !== 0 ? (
|
|
|
|
documents.map((document, index) => (
|
2023-05-23 08:28:37 +03:00
|
|
|
<DocumentItem
|
|
|
|
key={index}
|
|
|
|
document={document}
|
|
|
|
setDocuments={setDocuments}
|
|
|
|
/>
|
2023-05-22 21:24:18 +03:00
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<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">
|
|
|
|
<Button>Upload Files</Button>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-05-22 20:54:07 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-21 02:20:55 +03:00
|
|
|
}
|