about summary refs log tree commit diff
path: root/src/pages/Home.tsx
blob: 8bda03b0c9b0fe15eb28834b7fc74cd9831e120e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useEffect, useState, useCallback } from "react"

import { useNavigate } from "react-router-dom"

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 className="font-bold">Home</h1>
        <p>Logged in!</p>
        {files.map((file: any) => (
          <div key={file.id}>
            <p className="underline">file: {file.absolute_path}</p>
          </div>
        ))
        }
      </div>
    </>
  )
}