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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
import { useNavigate, useParams } from "react-router-dom"
import SideBar from "../components/Sidebar/Sidebar"
import { useCallback, useEffect, useState } from "react";
import { FSTracerFile } from "../lib/types";
export default function File(props: any) {
const navigate = useNavigate()
let { filepath } = useParams();
console.log("FILEPATH: ", filepath)
const [files, setFiles] = useState([])
const latestFile = files[0] as FSTracerFile | undefined
useEffect(() => {
if (!props.session) {
navigate('/login')
}
}, [props.session])
const fetchFiles = useCallback(async () => {
console.log("FETCHIN FILES")
const { data, error } = await props.supabase
.from('file')
.select()
.eq('absolute_path', filepath)
.order('timestamp', { ascending: false })
.range(0, 20)
if (error) {
console.error(error)
return
}
console.log("RAW FILES: ", data)
setFiles(data.map((file: any) => {
return file as File
}))
console.log("FETCHED FILES")
}, [props.supabase])
useEffect(() => {
fetchFiles()
}, [])
const formatFilePathAsName = (filepath: string) => {
const parts = filepath.split('/')
return parts[parts.length - 1]
}
return (
<>
<div className="flex h-screen">
<SideBar />
<main className="flex-1 overflow-y-auto my-4">
<div className="flex flex-col items-center">
{
formatFilePathAsName(filepath as string)// TODO: Filepath could be null
}
</div>
<div className="mt-5 flex flex-col items-center">
<div className="border rounded py-5 px-5">
{latestFile && <FileInfo file={latestFile} />
}
</div>
</div>
<div className="mt-5 flex flex-col items-center">
<div className="border rounded py-5 px-5">
{files.map((file: FSTracerFile) => (
<div key={file.id}>
<p>{file.absolute_path} - {file.timestamp}</p>
</div>
))
}
</div>
</div>
</main>
</div>
</>
)
}
interface FileInfoProps {
file: FSTracerFile
}
function FileInfo(props: FileInfoProps) {
return (
<>
<p>Absolute path: {props.file.absolute_path}</p>
<p>Timestamp: {props.file.timestamp}</p>
<p>Content: {props.file.contents}</p>
<p>ID: {props.file.id}</p>
</>
)
}
|