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 { fileID } = useParams(); console.log("FILEID: ", fileID) const [files, setFiles] = useState([]) const [file, setFile] = useState() const maxFilesToShow = 20; useEffect(() => { if (!props.session) { navigate('/login') } }, [props.session]) const fetchFiles = useCallback(async () => { console.log("FETCHING FILE") const { data: data1, error: err1 } = await props.supabase .from('file') .select() .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 (err2) { console.error(err2) return } console.log("RAW FILES: ", data2) setFiles(data2.map((file: any) => { return file as File })) console.log("FETCHED FILES") }, [props.supabase]) useEffect(() => { fetchFiles() }, [props.supabase]) const formatFilePathAsName = (filepath: string) => { const parts = filepath.split('/') return parts[parts.length - 1] } return ( <>
{fileID && file !== undefined ? <>
{ formatFilePathAsName(file.absolute_path) }
{files.map((currFile: FSTracerFile) => (

{currFile.absolute_path} - {currFile.timestamp} {currFile.id === file.id && "*"}

)) }
: <>

File not found

}
) } interface FileInfoProps { file: FSTracerFile } function FileInfo(props: FileInfoProps) { return ( <>

Absolute path: {props.file.absolute_path}

Timestamp: {props.file.timestamp}

Content: {props.file.contents}

ID: {props.file.id}

) }