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";
|
2023-01-07 18:31:39 -07:00
|
|
|
import {Dropdown, Menu} from "semantic-ui-react";
|
|
|
|
|
import {Media, StatusContext, ThemeContext} from "../contexts/contexts";
|
2022-08-06 05:22:07 +00:00
|
|
|
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
2022-10-25 15:57:44 -06:00
|
|
|
import {DarkModeToggle, HotspotStatusIcon, NAME} from "./Common";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2023-01-07 18:31:39 -07:00
|
|
|
const links = [{text: 'Videos', to: '/videos', key: 'videos'}, {
|
|
|
|
|
text: 'Archive', to: '/archive', key: 'archive'
|
|
|
|
|
}, {text: 'Map', to: '/map', key: 'map'}, {text: 'Files', to: '/files', key: 'files'}, {
|
|
|
|
|
text: 'Inventory', to: '/inventory', key: 'inventory'
|
|
|
|
|
}, {
|
|
|
|
|
key: 'apps', text: 'Apps', links: [{to: '/apps/otp', text: 'One Time Pad', end: true}, {
|
|
|
|
|
to: '/apps/statistics', text: 'Statistics', end: true
|
|
|
|
|
},]
|
|
|
|
|
},];
|
2022-11-04 09:19:51 -06:00
|
|
|
const admin = {to: '/admin', text: 'Admin', key: 'admin'};
|
2021-11-01 16:42:52 -06:00
|
|
|
const rightLinks = [admin,];
|
|
|
|
|
|
|
|
|
|
const collapsedLinks = links.concat([admin,]);
|
|
|
|
|
|
|
|
|
|
function DropdownLinks(props) {
|
2023-01-07 18:31:39 -07:00
|
|
|
return (<Dropdown item text={props.link.text}>
|
|
|
|
|
<Dropdown.Menu>
|
|
|
|
|
{props.link.links.map((l) => {
|
|
|
|
|
return (<MenuLink key={l.to} link={l}/>)
|
|
|
|
|
})}
|
|
|
|
|
</Dropdown.Menu>
|
|
|
|
|
</Dropdown>)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-11-04 09:19:51 -06:00
|
|
|
function MenuLink({link}) {
|
2022-01-29 22:25:35 -07:00
|
|
|
// Wrapper around NavLink to handle Navlink/Dropdown change.
|
2021-11-01 16:42:52 -06:00
|
|
|
let classes = 'item';
|
|
|
|
|
|
2022-11-04 09:19:51 -06:00
|
|
|
if (!link.links) {
|
|
|
|
|
const end = link.end ? {end: true} : {end: undefined};
|
2023-01-07 18:31:39 -07:00
|
|
|
return (<NavLink
|
|
|
|
|
className={classes}
|
|
|
|
|
to={link.to}
|
|
|
|
|
{...end}
|
|
|
|
|
>
|
|
|
|
|
{link.text}
|
|
|
|
|
</NavLink>)
|
2021-11-01 16:42:52 -06:00
|
|
|
} else {
|
2023-01-07 18:31:39 -07:00
|
|
|
return (<DropdownLinks link={link}/>)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 09:18:53 -06:00
|
|
|
function NavIcon(props) {
|
|
|
|
|
return <div style={{margin: '0.8em'}}>{props.children}</div>
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
export function NavBar() {
|
2022-10-16 11:53:44 -06:00
|
|
|
const {status} = useContext(StatusContext);
|
|
|
|
|
const wrol_mode = status ? status['wrol_mode'] : null;
|
2022-10-25 15:57:44 -06:00
|
|
|
const name = NAME || 'WROLPi';
|
|
|
|
|
const topNavText = wrol_mode ? <>{name} <Icon name='lock'/></> : name;
|
2022-08-06 05:22:07 +00:00
|
|
|
const {i} = useContext(ThemeContext);
|
|
|
|
|
|
2023-01-07 18:31:39 -07:00
|
|
|
const homeLink = <MenuLink link={{to: '/', text: topNavText, end: true}}/>;
|
|
|
|
|
const icons = <React.Fragment>
|
|
|
|
|
<NavIcon><HotspotStatusIcon/></NavIcon>
|
|
|
|
|
<NavIcon><DarkModeToggle/></NavIcon>
|
|
|
|
|
</React.Fragment>;
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2023-01-07 18:31:39 -07:00
|
|
|
return <>
|
|
|
|
|
<Media at='mobile'>
|
|
|
|
|
<Menu {...i}>
|
|
|
|
|
{homeLink}
|
|
|
|
|
<Menu.Menu position='right'>
|
|
|
|
|
{icons}
|
|
|
|
|
<Dropdown item icon="bars">
|
|
|
|
|
<Dropdown.Menu>
|
|
|
|
|
{collapsedLinks.map(i =><MenuLink link={i} key={i.key}/>)}
|
|
|
|
|
</Dropdown.Menu>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</Menu.Menu>
|
|
|
|
|
</Menu>
|
|
|
|
|
</Media>
|
|
|
|
|
<Media greaterThanOrEqual='tablet'>
|
|
|
|
|
<Menu {...i}>
|
|
|
|
|
{homeLink}
|
|
|
|
|
{links.map(i => <MenuLink link={i} key={i.key}/>)}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2023-01-07 18:31:39 -07:00
|
|
|
<Menu.Menu position='right'>
|
|
|
|
|
{icons}
|
|
|
|
|
{rightLinks.map(i => <MenuLink link={i} key={i.key}/>)}
|
|
|
|
|
</Menu.Menu>
|
|
|
|
|
</Menu>
|
|
|
|
|
</Media>
|
|
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|