centralized state (#221)

This commit is contained in:
Michael Quigley 2024-10-09 12:00:04 -04:00
parent f0cd66dbe2
commit c02b9c2b23
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 52 additions and 45 deletions

View File

@ -0,0 +1,35 @@
import {createBrowserRouter, RouterProvider} from "react-router-dom";
import Overview from "./Overview.jsx";
import ShareDetail from "./ShareDetail.jsx";
import {useEffect, useState} from "react";
import {AgentApi, ApiClient} from "./api/src/index.js";
const AgentUi = (props) => {
const [version, setVersion] = useState("");
let api = new AgentApi(new ApiClient(window.location.protocol+'//'+window.location.host));
useEffect(() => {
let mounted = true;
api.agentVersion((err, data) => {
if(mounted) {
setVersion(data.v);
}
});
}, []);
const router = createBrowserRouter([
{
path: "/",
element: <Overview version={version} />
},
{
path: "/share/:token",
element: <ShareDetail version={version} />
}
]);
return <RouterProvider router={router} />
}
export default AgentUi;

View File

@ -1,5 +1,3 @@
import {useEffect, useState} from "react";
import {AgentApi, ApiClient} from "./api/src/index.js";
import {AppBar, Button, IconButton, Toolbar, Typography} from "@mui/material";
import MenuIcon from "@mui/icons-material/Menu";
import {Link} from "react-router-dom";
@ -7,38 +5,25 @@ import ListIcon from "@mui/icons-material/List";
import LanIcon from "@mui/icons-material/Lan";
import ShareIcon from "@mui/icons-material/Share";
function NavBar() {
const [version, setVersion] = useState("");
let api = new AgentApi(new ApiClient(window.location.protocol+'//'+window.location.host));
useEffect(() => {
let mounted = true;
api.agentVersion((err, data) => {
if(mounted) {
setVersion(data.v);
}
});
}, []);
const NavBar = (props) => {
return (
<AppBar position={"static"}>
<Toolbar>
<IconButton
size={"large"}
size="large"
edge={"start"}
color={"inherit"}
color="inherit"
aria-label={"menu"}
sx={{mr: 2}}
>
<MenuIcon/>
</IconButton>
<Typography variant={"p"} component={"div"} sx={{flexGrow: 1}}>
zrok Agent { version !== "" ? " | " + version : ""}
<Typography variant="p" component={"div"} sx={{flexGrow: 1}}>
zrok Agent { props.version !== "" ? " | " + props.version : ""}
</Typography>
<Button color={"inherit"} component={Link} to={"/"}><ListIcon /></Button>
<Button color={"inherit"}><LanIcon /></Button>
<Button color={"inherit"}><ShareIcon /></Button>
<Button color="inherit" component={Link} to={"/"}><ListIcon /></Button>
<Button color="inherit"><LanIcon /></Button>
<Button color="inherit"><ShareIcon /></Button>
</Toolbar>
</AppBar>
)

View File

@ -4,7 +4,7 @@ import {AgentApi, ApiClient} from "./api/src/index.js";
import DataTable from "react-data-table-component";
import NavBar from "./NavBar.jsx";
function Overview() {
const Overview = (props) => {
const [shares, setShares] = useState([]);
const [accesses, setAccesses] = useState([]);
@ -67,7 +67,7 @@ function Overview() {
return (
<>
<NavBar />
<NavBar version={props.version} />
<div class={"info"}>
<h2>Shares</h2>

View File

@ -1,12 +1,12 @@
import NavBar from "./NavBar.jsx";
import {useParams} from "react-router-dom";
function ShareDetail() {
const ShareDetail = (props) => {
let params = useParams();
return (
<>
<NavBar />
<NavBar version={props.version} />
<h1>Share {params.token}</h1>
</>

View File

@ -1,23 +1,10 @@
import './index.css';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import Overview from "./Overview.jsx";
import ShareDetail from "./ShareDetail.jsx";
const router = createBrowserRouter([
{
path: "/",
element: <Overview />
},
{
path: "/share/:token",
element: <ShareDetail />
}
]);
import "./index.css";
import {StrictMode} from "react";
import {createRoot} from "react-dom/client";
import AgentUi from "./AgentUi.jsx";
createRoot(document.getElementById('root')).render(
<StrictMode>
<RouterProvider router={router} />
<AgentUi />
</StrictMode>,
)