import { faFile, faFolder } from "@fortawesome/free-solid-svg-icons" import { CloudUpload, CreateNewFolder } from "@mui/icons-material" import { IconButton, 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 { resolve as pathResolve } from 'path' import api from '../../api_utils' import Icon from "../../components/other/icon" import Table from "../../components/user/table" import UploadModal from "../../components/user/modals/upload" import CreateFolderModal from "../../components/user/modals/create-folder" import IconDiv from "../../components/other/icon-div" 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)) } const refreshFolder = () => refresh(path) useEffect(() => { const params = new URLSearchParams(window.location.search) const path = params.get("path") || "" api.list(path, cookies.token) .then(data => { setPath(path) setFolders(data.dirs) setFiles(data.files) }) .catch(err => console.error(err)) }, [cookies]) // modals const [uploadModal, setUploadModal] = useState(false) const [createFolderModal, setCreateFolderModal] = useState(false) return ( <> Files - HomeDisk setUploadModal(true)} > setCreateFolderModal(true)} > {path != "" && path != "/" && ( )} {folders.map((f, index) => )} {files.map((f, index) => )}
Name Size Modified
refresh(pathResolve(path, '..'))}> .. (go up)
) } 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 }