From 6b8b2d50918c86a1785e26eb2e03c02bfa021b88 Mon Sep 17 00:00:00 2001
From: Manuel Palenzuela Merino
Date: Sat, 13 Jul 2024 09:55:44 +0200
Subject: Pages: File: Have path be based on fileID instead of path
---
src/App.tsx | 4 +--
src/components/Other/FSTracerFile.tsx | 2 +-
src/pages/File.tsx | 52 +++++++++++++++++++++++------------
3 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/src/App.tsx b/src/App.tsx
index 8d5ebb4..98f216c 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -43,8 +43,8 @@ function App() {
} />
-
+
} />
notfound
} />
diff --git a/src/components/Other/FSTracerFile.tsx b/src/components/Other/FSTracerFile.tsx
index 61c8e35..2bc58b4 100644
--- a/src/components/Other/FSTracerFile.tsx
+++ b/src/components/Other/FSTracerFile.tsx
@@ -6,7 +6,7 @@ interface FileComponentProps {
export default function FileComponent(props: FileComponentProps) {
return (
-
+
file: {props.file.absolute_path}
)
diff --git a/src/pages/File.tsx b/src/pages/File.tsx
index bbbdac2..f9f1a73 100644
--- a/src/pages/File.tsx
+++ b/src/pages/File.tsx
@@ -5,13 +5,12 @@ import { FSTracerFile } from "../lib/types";
export default function File(props: any) {
const navigate = useNavigate()
- let { filepath } = useParams();
+ let { fileID } = useParams();
- console.log("FILEPATH: ", filepath)
+ console.log("FILEID: ", fileID)
const [files, setFiles] = useState([])
-
- const latestFile = files[0] as FSTracerFile | undefined
+ const [file, setFile] = useState()
const maxFilesToShow = 20;
@@ -22,19 +21,36 @@ export default function File(props: any) {
}, [props.session])
const fetchFiles = useCallback(async () => {
- console.log("FETCHIN FILES")
- const { data, error } = await props.supabase
+ console.log("FETCHING FILE")
+ const { data: data1, error: err1 } = await props.supabase
.from('file')
.select()
- .eq('absolute_path', filepath)
+ .eq('id', fileID)
+ if (err1) {
+ console.error(err1)
+ return
+ }
+
+ if (data1.length === 0) {
+ return
+ }
+
+ let fetchedFile = data1[0] as FSTracerFile;
+ setFile(fetchedFile)
+
+ console.log("FETCHIN FILES", JSON.stringify(fetchedFile))
+ const { data: data2, error: err2 } = await props.supabase
+ .from('file')
+ .select()
+ .eq('absolute_path', fetchedFile.absolute_path)
.order('timestamp', { ascending: false })
.range(0, maxFilesToShow)
- if (error) {
- console.error(error)
+ if (err2) {
+ console.error(err2)
return
}
- console.log("RAW FILES: ", data)
- setFiles(data.map((file: any) => {
+ console.log("RAW FILES: ", data2)
+ setFiles(data2.map((file: any) => {
return file as File
}))
console.log("FETCHED FILES")
@@ -42,7 +58,7 @@ export default function File(props: any) {
useEffect(() => {
fetchFiles()
- }, [])
+ }, [props.supabase])
const formatFilePathAsName = (filepath: string) => {
const parts = filepath.split('/')
@@ -54,22 +70,22 @@ export default function File(props: any) {
- {filepath && latestFile ? <>
+ {fileID && file !== undefined ? <>
{
- formatFilePathAsName(filepath)
+ formatFilePathAsName(file.absolute_path)
}
- {files.map((file: FSTracerFile) => (
-
-
{file.absolute_path} - {file.timestamp}
+ {files.map((currFile: FSTracerFile) => (
+
+
{currFile.absolute_path} - {currFile.timestamp} {currFile.id === file.id && "*"}
))
}
--
cgit 1.4.1