mirror of
https://github.com/openziti/zrok.git
synced 2024-11-26 18:13:52 +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 {AppBar, Button, IconButton, Toolbar, Typography} from "@mui/material";
|
||||||
import MenuIcon from "@mui/icons-material/Menu";
|
import MenuIcon from "@mui/icons-material/Menu";
|
||||||
import {Link} from "react-router-dom";
|
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 LanIcon from "@mui/icons-material/Lan";
|
||||||
import ShareIcon from "@mui/icons-material/Share";
|
import ShareIcon from "@mui/icons-material/Share";
|
||||||
|
|
||||||
function NavBar() {
|
const NavBar = (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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppBar position={"static"}>
|
<AppBar position={"static"}>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<IconButton
|
<IconButton
|
||||||
size={"large"}
|
size="large"
|
||||||
edge={"start"}
|
edge={"start"}
|
||||||
color={"inherit"}
|
color="inherit"
|
||||||
aria-label={"menu"}
|
aria-label={"menu"}
|
||||||
sx={{mr: 2}}
|
sx={{mr: 2}}
|
||||||
>
|
>
|
||||||
<MenuIcon/>
|
<MenuIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Typography variant={"p"} component={"div"} sx={{flexGrow: 1}}>
|
<Typography variant="p" component={"div"} sx={{flexGrow: 1}}>
|
||||||
zrok Agent { version !== "" ? " | " + version : ""}
|
zrok Agent { props.version !== "" ? " | " + props.version : ""}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button color={"inherit"} component={Link} to={"/"}><ListIcon /></Button>
|
<Button color="inherit" component={Link} to={"/"}><ListIcon /></Button>
|
||||||
<Button color={"inherit"}><LanIcon /></Button>
|
<Button color="inherit"><LanIcon /></Button>
|
||||||
<Button color={"inherit"}><ShareIcon /></Button>
|
<Button color="inherit"><ShareIcon /></Button>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,7 @@ import {AgentApi, ApiClient} from "./api/src/index.js";
|
|||||||
import DataTable from "react-data-table-component";
|
import DataTable from "react-data-table-component";
|
||||||
import NavBar from "./NavBar.jsx";
|
import NavBar from "./NavBar.jsx";
|
||||||
|
|
||||||
function Overview() {
|
const Overview = (props) => {
|
||||||
const [shares, setShares] = useState([]);
|
const [shares, setShares] = useState([]);
|
||||||
const [accesses, setAccesses] = useState([]);
|
const [accesses, setAccesses] = useState([]);
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ function Overview() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NavBar />
|
<NavBar version={props.version} />
|
||||||
|
|
||||||
<div class={"info"}>
|
<div class={"info"}>
|
||||||
<h2>Shares</h2>
|
<h2>Shares</h2>
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import NavBar from "./NavBar.jsx";
|
import NavBar from "./NavBar.jsx";
|
||||||
import {useParams} from "react-router-dom";
|
import {useParams} from "react-router-dom";
|
||||||
|
|
||||||
function ShareDetail() {
|
const ShareDetail = (props) => {
|
||||||
let params = useParams();
|
let params = useParams();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NavBar />
|
<NavBar version={props.version} />
|
||||||
|
|
||||||
<h1>Share {params.token}</h1>
|
<h1>Share {params.token}</h1>
|
||||||
</>
|
</>
|
||||||
|
@ -1,23 +1,10 @@
|
|||||||
import './index.css';
|
import "./index.css";
|
||||||
import { StrictMode } from 'react';
|
import {StrictMode} from "react";
|
||||||
import { createRoot } from 'react-dom/client';
|
import {createRoot} from "react-dom/client";
|
||||||
import { createBrowserRouter, RouterProvider } from "react-router-dom";
|
import AgentUi from "./AgentUi.jsx";
|
||||||
import Overview from "./Overview.jsx";
|
|
||||||
import ShareDetail from "./ShareDetail.jsx";
|
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
|
||||||
{
|
|
||||||
path: "/",
|
|
||||||
element: <Overview />
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/share/:token",
|
|
||||||
element: <ShareDetail />
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<RouterProvider router={router} />
|
<AgentUi />
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user