import { useEffect, useState } from "react"; import { useVersion } from "./store/version"; import FileView from "./components/file-view"; import Directory from "./components/directory"; import { DirEntry, usePath } from "./store/path"; import { DynamicIcon } from "lucide-react/dynamic"; import { BrowserRouter, Route, Routes, useLocation } from "react-router"; import "./App.scss"; import kuma from "./assets/kuma.png"; import NotFound from "./components/notfound"; import Login from "./components/login"; import { AccountData, useAuthStore } from "./store/auth"; import Logout from "./components/logout"; import Settings from "./components/settings"; import { FileNavigator } from "./components/navigation"; function App() { return ( } />} /> } /> } />} /> } />} /> ); } function Dashboard({ children }: { children: React.ReactNode }) { return (
{children}
); } function View() { const path = usePath(); const location = useLocation(); const [load, setLoad] = useState(false); useEffect(() => { if (!load) { path.update(location.pathname.substring(1, location.pathname.length)).then(() => { setLoad(true); }); return; } }, [load, path, location]); if (!load) { return <>; } if (typeof path.data === "undefined") { return ; } if (path.data.is_dir) { return ; } return ; } function Header() { const auth = useAuthStore(); const [isAuth, setAuth] = useState(false); const [username, setUsername] = useState("undefined"); useEffect(() => { if (auth.token === null) { return; } auth.checkToken(auth.token).then((ok) => { if (ok) setAuth(true); }); fetch("/api/auth/read", { method: "GET", mode: "same-origin", headers: { "Authorization": `Basic ${auth.token}` } }).then(res => { if (res.status !== 200) return; return res.json(); }).then((data: AccountData) => { setUsername(data.username); }); }, [auth, isAuth]); return ( ); } function Footer() { const path = usePath(); let file = 0; let dir = 0; const version = useVersion(); const [load, setLoad] = useState(false); if (typeof path.data !== "undefined") { if (path.data.is_dir) { path.data.entries.forEach((entry: DirEntry) => { if (entry.is_dir) { dir += 1; } else { file += 1; } }); } } useEffect(() => { if (!load) { version.update().then(() => { setLoad(true); }); return; } }, [load, version]); return ( ); } export default App;