2022-08-06 05:22:07 +00:00
|
|
|
import React, {useContext} from "react";
|
2021-11-01 16:42:52 -06:00
|
|
|
import {NavLink} from "react-router-dom";
|
|
|
|
|
import {Dropdown, Menu, Responsive} from "semantic-ui-react";
|
2022-10-16 11:53:44 -06:00
|
|
|
import {StatusContext, ThemeContext} from "../contexts/contexts";
|
2022-08-06 05:22:07 +00:00
|
|
|
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
|
|
|
|
import {DarkModeToggle} from "./Common";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
const responsiveWidth = 500;
|
|
|
|
|
|
|
|
|
|
const links = [
|
2022-02-02 14:02:51 -07:00
|
|
|
{text: 'Videos', to: '/videos', key: 'videos'},
|
|
|
|
|
{text: 'Archive', to: '/archive', key: 'archive'},
|
2022-03-08 13:26:03 -07:00
|
|
|
{text: 'Map', to: '/map', key: 'map'},
|
2022-02-02 14:02:51 -07:00
|
|
|
{text: 'Files', to: '/files', key: 'files'},
|
2022-03-08 13:26:03 -07:00
|
|
|
{text: 'Inventory', to: '/inventory', key: 'inventory'},
|
2021-11-01 16:42:52 -06:00
|
|
|
{
|
2022-02-02 14:02:51 -07:00
|
|
|
key: 'apps', text: 'Apps', links: [
|
2021-11-01 16:42:52 -06:00
|
|
|
{to: '/apps/otp', text: 'One Time Pad', exact: true},
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
];
|
2022-02-02 14:02:51 -07:00
|
|
|
const admin = {to: '/admin', text: 'Admin', exact: true, key: 'admin'};
|
2021-11-01 16:42:52 -06:00
|
|
|
const rightLinks = [admin,];
|
|
|
|
|
|
|
|
|
|
const collapsedLinks = links.concat([admin,]);
|
|
|
|
|
|
|
|
|
|
function DropdownLinks(props) {
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown item text={props.link.text}>
|
|
|
|
|
<Dropdown.Menu>
|
|
|
|
|
{props.link.links.map((l) => {
|
|
|
|
|
return (
|
2022-01-29 22:25:35 -07:00
|
|
|
<MenuLink key={l.to} link={l}/>
|
2021-11-01 16:42:52 -06:00
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</Dropdown.Menu>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
function MenuLink(props) {
|
|
|
|
|
// Wrapper around NavLink to handle Navlink/Dropdown change.
|
2021-11-01 16:42:52 -06:00
|
|
|
let classes = 'item';
|
|
|
|
|
if (props.link.header) {
|
|
|
|
|
classes = `${classes} header`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!props.link.links) {
|
2022-08-06 05:22:07 +00:00
|
|
|
const exact = props.link.exact ? {exact: null} : {};
|
2021-11-01 16:42:52 -06:00
|
|
|
return (
|
|
|
|
|
<NavLink
|
|
|
|
|
className={classes}
|
|
|
|
|
to={props.link.to}
|
2022-08-06 05:22:07 +00:00
|
|
|
{...exact}
|
2021-11-01 16:42:52 -06:00
|
|
|
>
|
|
|
|
|
{props.link.text}
|
|
|
|
|
</NavLink>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<DropdownLinks link={props.link}/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function NavBar() {
|
2022-10-16 11:53:44 -06:00
|
|
|
const {status} = useContext(StatusContext);
|
|
|
|
|
const wrol_mode = status ? status['wrol_mode'] : null;
|
2022-08-06 05:22:07 +00:00
|
|
|
const topNavText = wrol_mode ? <>WROLPi <Icon name='lock'/></> : 'WROLPi';
|
|
|
|
|
const {i} = useContext(ThemeContext);
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
return (
|
2022-08-06 05:22:07 +00:00
|
|
|
<Menu {...i}>
|
2021-11-01 16:42:52 -06:00
|
|
|
{/*Always show WROLPi home button*/}
|
2022-08-06 05:22:07 +00:00
|
|
|
<MenuLink link={{to: '/', text: topNavText, exact: true}}/>
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
{/*Show the links in a menu when on desktop*/}
|
|
|
|
|
{links.map((link) => {
|
|
|
|
|
return (
|
2022-02-02 14:02:51 -07:00
|
|
|
<Responsive minWidth={responsiveWidth} as={MenuLink} link={link} key={link.key}/>
|
2021-11-01 16:42:52 -06:00
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
<Responsive minWidth={responsiveWidth} as={Menu.Menu} position="right">
|
2022-08-06 05:22:07 +00:00
|
|
|
<div style={{margin: '0.8em'}}>
|
|
|
|
|
<DarkModeToggle/>
|
|
|
|
|
</div>
|
2022-02-02 14:02:51 -07:00
|
|
|
{rightLinks.map((link) => <MenuLink link={link} key={link.key}/>)}
|
2021-11-01 16:42:52 -06:00
|
|
|
</Responsive>
|
|
|
|
|
|
|
|
|
|
{/*Show the menu items in a dropdown when on mobile*/}
|
|
|
|
|
<Responsive as={Menu.Menu} maxWidth={responsiveWidth - 1} position='right'>
|
2022-08-06 05:22:07 +00:00
|
|
|
<div style={{margin: '0.8em'}}>
|
|
|
|
|
<DarkModeToggle/>
|
|
|
|
|
</div>
|
2021-11-01 16:42:52 -06:00
|
|
|
<Dropdown item icon="bars">
|
|
|
|
|
<Dropdown.Menu>
|
2022-02-02 14:02:51 -07:00
|
|
|
{collapsedLinks.map((link) =>
|
|
|
|
|
<MenuLink link={link} key={link.key}/>
|
|
|
|
|
)}
|
2021-11-01 16:42:52 -06:00
|
|
|
</Dropdown.Menu>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</Responsive>
|
|
|
|
|
</Menu>
|
|
|
|
|
)
|
|
|
|
|
}
|