mirror of
https://github.com/openziti/zrok.git
synced 2024-11-23 00:23:48 +01:00
centralized state (#221)
This commit is contained in:
parent
f0cd66dbe2
commit
c02b9c2b23
35
agent/agentUi/src/AgentUi.jsx
Normal file
35
agent/agentUi/src/AgentUi.jsx
Normal 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;
|
@ -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>
|
||||
)
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
</>
|
||||
|
@ -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>,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user