import { faFile, faFolder } from "@fortawesome/free-solid-svg-icons" import { Link as MuiLink } from "@mui/material" import Head from 'next/head' import Link from 'next/link' import { useEffect, useState } from 'react' import { useCookies } from 'react-cookie' import api from '../../api_utils' import Icon from "../../components/other/icon" import Table from "../../components/user/table" export default function Files() { const [cookies] = useCookies(["token"]) const [path, setPath] = useState("") const [files, setFiles] = useState([{ name: "", size: "", modified: "" }]) const [folders, setFolders] = useState([{ name: "", size: "", modified: "" }]) const refresh = (path: string) => { api.list(path, cookies.token) .then(data => { setPath(path) setFolders(data.dirs) setFiles(data.files) }) .catch(err => console.error(err)) } useEffect(() => { const params = new URLSearchParams(window.location.search) const path = params.get("dir") || "" api.list(path, cookies.token) .then(data => { setPath(path) setFolders(data.dirs) setFiles(data.files) }) .catch(err => console.error(err)) }, [cookies]) return ( <> Files - HomeDisk {folders.map((f, index) => )} {files.map((f, index) => )}
Name Size Modified
) } function FolderComponent({ name, path, size, modified, refresh }: Props) { return ( refresh(path)}> {name.replace("/", "")} {size} {modified} ) } function FileComponent({ name, path, size, modified, refresh }: Props) { return ( refresh(path)}> {name.replace("/", "")} {size} {modified} ago ) } type Props = { name: string, path: string, size: string, modified: string, // eslint-disable-next-line no-unused-vars refresh: (path: string) => void }