You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

import { observer } from "mobx-react";
import * as React from "react";
import { Link } from "react-router-dom";
import { Menu } from "semantic-ui-react";
7 years ago
import * as route from "@client/routePaths";
import { AppState, ConsumeState, injectState } from "@client/state";
interface NavItemProps {
to: string;
children: React.ReactNode;
}
const NavItem = observer(({ to, children }: NavItemProps) => {
function consumeState(appState: AppState) {
const { location } = appState.routerStore;
return (
<Menu.Item as={Link} to={to} active={location.pathname.startsWith(to)}>
{children}
</Menu.Item>
);
}
return <ConsumeState>{consumeState}</ConsumeState>;
});
function NavBar({ appState }: { appState: AppState }) {
let loginMenu;
// tslint:disable-next-line:prefer-conditional-expression
if (appState.isLoggedIn) {
loginMenu = <NavItem to={route.logout}>Logout</NavItem>;
} else {
loginMenu = <NavItem to={route.login}>Login</NavItem>;
}
return (
<Menu>
<NavItem to={route.device()}>Devices</NavItem>
<NavItem to={route.messagesTest}>Messages test</NavItem>
<Menu.Menu position="right">{loginMenu}</Menu.Menu>
</Menu>
);
}
export default observer(injectState(NavBar));