diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-06-06 00:08:54 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-06-06 00:08:54 +0200 |
commit | 970a9afa9ee6c22c6643d31d77d53c33d15bace4 (patch) | |
tree | 9f6f426c75ef8b6cf95ae6feb67894f8440a00c4 | |
parent | Pages: Add Home and route conditionally based on login (diff) | |
download | fs-tracer-frontend-970a9afa9ee6c22c6643d31d77d53c33d15bace4.tar.gz fs-tracer-frontend-970a9afa9ee6c22c6643d31d77d53c33d15bace4.tar.bz2 fs-tracer-frontend-970a9afa9ee6c22c6643d31d77d53c33d15bace4.zip |
Home: Get and show files
-rw-r--r-- | src/pages/Home.tsx | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 624681a..1a5853b 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -1,21 +1,54 @@ -import { useEffect } from "react" +import { useEffect, useState, useCallback } from "react" import { useNavigate } from "react-router-dom" +interface File { + id: number + user_id: string + absolute_path: string + contents: string + timestamp: string +} + export default function Home(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 ( <> <div> <h1>Home</h1> - <p>Logged in to access your account: {JSON.stringify(props.session)}</p> + <p>Logged in!</p> + {files.map((file: any) => ( + <div key={file.id}> + <p>file: {file.absolute_path}</p> + </div> + )) + } </div> </> ) |