From 3bd85c658af0592f6cbde6ba97d8bbfe879e0321 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Mon, 1 Jul 2024 13:26:43 +0200 Subject: Pages: Add Recents page --- src/App.tsx | 3 +++ src/pages/Home.tsx | 10 +--------- src/pages/Recent.tsx | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 src/pages/Recent.tsx (limited to 'src') diff --git a/src/App.tsx b/src/App.tsx index ffbb8f3..5304a62 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,9 @@ function App() { } /> + + } /> } /> diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 9c86a9f..37cc7cc 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -7,7 +7,7 @@ import LineGraph from "../components/Graphs/LineGraph" export default function Home(props: any) { const navigate = useNavigate() - const [files, setFiles] = useState([]) + const [_, setFiles] = useState([]) useEffect(() => { if (!props.session) { @@ -43,14 +43,6 @@ export default function Home(props: any) {
-
- {files.map((file: any) => ( -
-

file: {file.absolute_path}

-
- )) - } -
diff --git a/src/pages/Recent.tsx b/src/pages/Recent.tsx new file mode 100644 index 0000000..cecef25 --- /dev/null +++ b/src/pages/Recent.tsx @@ -0,0 +1,51 @@ +import { useEffect, useState, useCallback } from "react" + +import { useNavigate } from "react-router-dom" +import SideBar from "../components/Sidebar/Sidebar" + +export default function Recent(props: any) { + const navigate = useNavigate() + + const [files, setFiles] = useState([]) + + useEffect(() => { + if (!props.session) { + navigate('/login') + } + }, [props.session]) + + const fetchFiles = useCallback(async () => { + const { data, error } = await props.supabase + .from('file') + .select() + if (error) { + console.error(error) + return + } + setFiles(data.map((file: any) => { + return file as File + })) + }, [props.supabase]) + + useEffect(() => { + fetchFiles() + }, []) + + return ( + <> +
+ +
+
+ {files.map((file: any) => ( +
+

file: {file.absolute_path}

+
+ )) + } +
+
+
+ + ) +} -- cgit 1.4.1