import React from 'react'; import { NavLink } from 'react-router-dom'; import { IClaims } from '../../model'; import { OauthService, StorageService } from '../../services'; import './navbar.scss'; interface Props { claims?: IClaims; open: boolean; onNavClick: () => void; } interface State { oauthUrl?: string; } export class Navbar extends React.Component { constructor(props: Props) { super(props); this.state = {}; } componentDidMount() { this.loadOauthUrl(); } async loadOauthUrl() { const oauthUrl = await OauthService.getOauthUrl(); if (oauthUrl) { this.setState({ oauthUrl }); } } private logout = () => { StorageService.clear(); window.location.href = '/'; }; renderLoginButton() { const { claims } = this.props; if (!this.state.oauthUrl) { return null; } return !claims ? ( Login ) : ( Logout ); } renderNavLink = (title: string, to: string, params?: any) => { return ( {title} ); }; render() { const { claims, open } = this.props; const openClass = open ? 'navbar--open' : ''; return (
{this.renderNavLink('Soundboard', '/', { exact: true })} {this.renderNavLink('Video Archive', '/video-archive')} {this.renderNavLink('Youtube Downloader', '/downloader')} {this.renderNavLink('Clips', '/clips')} {this.renderNavLink('Stats', '/stats')} {this.renderLoginButton()} {claims && claims.email &&
{claims.email}
}
); } }