import { useEffect, useState, useCallback } from "react" import { useNavigate } from "react-router-dom" import SideBar from "../components/Sidebar/Sidebar" import { FSTracerFile } from "../lib/types"; import FileComponent from "../components/Other/FSTracerFile"; export default function Search(props: any) { const navigate = useNavigate() const numOfFilesToShow = 20; const [files, setFiles] = useState([]) const [search, setSearch] = useState("") const [paginationOffset, setPaginationOffset] = useState(0); useEffect(() => { if (!props.session) { navigate('/login') } }, [props.session]) const fetchFiles = useCallback(async () => { console.log("FETCHIN FILES, pagination: ", paginationOffset, " search: ", search) const { data, error } = await props.supabase .from('file') .select() .ilike('absolute_path', `%${search}%`) .range(paginationOffset, paginationOffset + numOfFilesToShow - 1) 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, paginationOffset, search]) useEffect(() => { fetchFiles() }, [paginationOffset]) return ( <>