wrolpi/app/src/components/Nav.js
Roland 6fa6be50fe
Stopping renderd when reseting map db.
Skipping channel import during test unless explicitly requested.

Deleting gis database during upgrade, if user agrees.  Increasing API verbosity.

Using status context to prevent fetching status in useHotspot.

Disabling wifi toggle button when pending.

Toggling hotspot when clicking nav hotspot icon.

Displaying Hotspot status icon in nav menu.

Importing channels/favorites after refreshing.

Refresh tasks cancel when server shuts down.

Bumping version for release speed.

Refreshing files is 3x faster.

Creating useRecurringTimeout hook which repeatedly calls a callback after a timeout.

Changing intervals to timeout so fetches don't stack up while server is loaded.

Checking that video file exists before fetching.

Creating release candidate branch.  Not indexing model associated files.
2022-10-21 15:21:57 -06:00

107 lines
3.5 KiB
JavaScript

import React, {useContext} from "react";
import {NavLink} from "react-router-dom";
import {Dropdown, Menu, Responsive} from "semantic-ui-react";
import {StatusContext, ThemeContext} from "../contexts/contexts";
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
import {DarkModeToggle, HotspotStatusIcon} from "./Common";
const responsiveWidth = 500;
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', exact: true},
]
},
];
const admin = {to: '/admin', text: 'Admin', exact: true, key: 'admin'};
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 (
<MenuLink key={l.to} link={l}/>
)
})}
</Dropdown.Menu>
</Dropdown>
)
}
function MenuLink(props) {
// Wrapper around NavLink to handle Navlink/Dropdown change.
let classes = 'item';
if (props.link.header) {
classes = `${classes} header`;
}
if (!props.link.links) {
const exact = props.link.exact ? {exact: null} : {};
return (
<NavLink
className={classes}
to={props.link.to}
{...exact}
>
{props.link.text}
</NavLink>
)
} else {
return (
<DropdownLinks link={props.link}/>
)
}
}
function NavIcon(props) {
return <div style={{margin: '0.8em'}}>{props.children}</div>
}
export function NavBar() {
const {status} = useContext(StatusContext);
const wrol_mode = status ? status['wrol_mode'] : null;
const topNavText = wrol_mode ? <>WROLPi&nbsp; <Icon name='lock'/></> : 'WROLPi';
const {i} = useContext(ThemeContext);
return (
<Menu {...i}>
{/*Always show WROLPi home button*/}
<MenuLink link={{to: '/', text: topNavText, exact: true}}/>
{/*Show the links in a menu when on desktop*/}
{links.map((link) => {
return (
<Responsive minWidth={responsiveWidth} as={MenuLink} link={link} key={link.key}/>
)
})}
<Responsive minWidth={responsiveWidth} as={Menu.Menu} position="right">
<NavIcon><HotspotStatusIcon/></NavIcon>
<NavIcon><DarkModeToggle/></NavIcon>
{rightLinks.map((link) => <MenuLink link={link} key={link.key}/>)}
</Responsive>
{/*Show the menu items in a dropdown when on mobile*/}
<Responsive as={Menu.Menu} maxWidth={responsiveWidth - 1} position='right'>
<NavIcon><HotspotStatusIcon/></NavIcon>
<NavIcon><DarkModeToggle/></NavIcon>
<Dropdown item icon="bars">
<Dropdown.Menu>
{collapsedLinks.map((link) =>
<MenuLink link={link} key={link.key}/>
)}
</Dropdown.Menu>
</Dropdown>
</Responsive>
</Menu>
)
}