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-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">
|
|
|
|
{documents.map((document, index) => (
|
|
|
|
<DocumentItem key={index} document={document} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-21 02:20:55 +03:00
|
|
|
}
|