Skip to content

Commit

Permalink
react router (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Oct 8, 2024
1 parent a67dba0 commit c5c5bb0
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 53 deletions.
42 changes: 42 additions & 0 deletions agent/agentUi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/agentUi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-bootstrap": "^2.10.5",
"react-data-table-component": "^7.6.2",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.2",
"superagent": "^10.1.0"
},
"devDependencies": {
Expand Down
9 changes: 0 additions & 9 deletions agent/agentUi/src/App.css

This file was deleted.

47 changes: 47 additions & 0 deletions agent/agentUi/src/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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";
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);
}
});
}, []);

return (
<AppBar position={"static"}>
<Toolbar>
<IconButton
size={"large"}
edge={"start"}
color={"inherit"}
aria-label={"menu"}
sx={{mr: 2}}
>
<MenuIcon/>
</IconButton>
<Typography variant={"p"} component={"div"} sx={{flexGrow: 1}}>
zrok Agent { version !== "" ? " | " + version : ""}
</Typography>
<Button color={"inherit"} component={Link} to={"/"}><ListIcon /></Button>
<Button color={"inherit"}><LanIcon /></Button>
<Button color={"inherit"}><ShareIcon /></Button>
</Toolbar>
</AppBar>
)
}

export default NavBar;
43 changes: 4 additions & 39 deletions agent/agentUi/src/App.jsx → agent/agentUi/src/Overview.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import {useEffect, useState} from "react";
import {AgentApi, ApiClient} from "./api/src/index.js";
import DataTable from "react-data-table-component";
import ShareIcon from "@mui/icons-material/Share";
import MenuIcon from "@mui/icons-material/Menu";
import LanIcon from "@mui/icons-material/Lan";
import ListIcon from "@mui/icons-material/List";
import {AppBar, Button, IconButton, Toolbar, Typography} from "@mui/material";
import NavBar from "./NavBar.jsx";

function App() {
const [version, setVersion] = useState("");
function Overview() {
const [shares, setShares] = useState([]);
const [accesses, setAccesses] = useState([]);

Expand Down Expand Up @@ -55,15 +49,6 @@ function App() {

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);
}
});
}, []);

useEffect(() => {
let mounted = true;
let interval = setInterval(() => {
Expand All @@ -82,25 +67,7 @@ function App() {

return (
<>
<AppBar position={"static"}>
<Toolbar>
<IconButton
size={"large"}
edge={"start"}
color={"inherit"}
aria-label={"menu"}
sx={{mr: 2}}
>
<MenuIcon/>
</IconButton>
<Typography variant={"p"} component={"div"} sx={{flexGrow: 1}}>
zrok Agent { version !== "" ? " | " + version : ""}
</Typography>
<Button color={"inherit"}><ListIcon /></Button>
<Button color={"inherit"}><LanIcon /></Button>
<Button color={"inherit"}><ShareIcon /></Button>
</Toolbar>
</AppBar>
<NavBar />

<div class={"info"}>
<h2>Shares</h2>
Expand All @@ -119,10 +86,8 @@ function App() {
noDataComponent={<div/>}
/>
</div>

<code>Connected Version: {version}</code>
</>
)
}

export default App;
export default Overview;
12 changes: 12 additions & 0 deletions agent/agentUi/src/ShareDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import NavBar from "./NavBar.jsx";

function ShareDetail() {
return (
<>
<NavBar />
<h1>Share Detail</h1>
</>
)
}

export default ShareDetail;
10 changes: 10 additions & 0 deletions agent/agentUi/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
}

.info {
margin-top: 5em;
}
23 changes: 18 additions & 5 deletions agent/agentUi/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.jsx'
import './index.css'
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",
element: <ShareDetail />
}
]);

createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
<RouterProvider router={router} />
</StrictMode>,
)

0 comments on commit c5c5bb0

Please sign in to comment.