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.
48 lines
1.3 KiB
48 lines
1.3 KiB
7 years ago
|
import { observer } from "mobx-react";
|
||
7 years ago
|
import * as React from "react";
|
||
|
import { Link } from "react-router-dom";
|
||
|
import { Menu } from "semantic-ui-react";
|
||
|
|
||
7 years ago
|
import * as rp from "@client/routePaths";
|
||
|
import { AppState, ConsumeState, injectState } from "@client/state";
|
||
7 years ago
|
|
||
7 years ago
|
interface NavItemProps {
|
||
|
to: string;
|
||
|
children: React.ReactNode;
|
||
|
}
|
||
|
|
||
7 years ago
|
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>);
|
||
|
});
|
||
7 years ago
|
|
||
7 years ago
|
function NavBar({ appState }: { appState: AppState }) {
|
||
|
let loginMenu;
|
||
|
if (appState.isLoggedIn) {
|
||
|
loginMenu = (
|
||
7 years ago
|
<NavItem to={rp.logout}>Logout</NavItem>
|
||
7 years ago
|
);
|
||
|
} else {
|
||
|
loginMenu = (
|
||
7 years ago
|
<NavItem to={rp.login}>Login</NavItem>
|
||
7 years ago
|
);
|
||
|
}
|
||
7 years ago
|
return (
|
||
|
<Menu>
|
||
7 years ago
|
<NavItem to={rp.device("grinklers")}>Device grinklers</NavItem>
|
||
|
<NavItem to={rp.messagesTest}>Messages test</NavItem>
|
||
7 years ago
|
<Menu.Menu position="right">
|
||
7 years ago
|
{loginMenu}
|
||
7 years ago
|
</Menu.Menu>
|
||
7 years ago
|
</Menu>
|
||
|
);
|
||
|
}
|
||
|
|
||
7 years ago
|
export default observer(injectState(NavBar));
|