import Divider from '@material-ui/core/Divider'; import Drawer from '@material-ui/core/Drawer'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; import {StyleRules, Theme, WithStyles, withStyles} from '@material-ui/core/styles'; import React, {Component} from 'react'; import {Link} from 'react-router-dom'; import AppStore from '../stores/AppStore'; const styles = (theme: Theme): StyleRules<'drawerPaper' | 'toolbar' | 'link'> => ({ drawerPaper: { position: 'relative', width: 250, minHeight: '100%', height: '100vh', }, toolbar: theme.mixins.toolbar, link: { color: 'inherit', textDecoration: 'none', }, }); type Styles = WithStyles<'drawerPaper' | 'toolbar' | 'link'>; interface IProps { loggedIn: boolean; } interface IState { apps: IApplication[]; } class Navigation extends Component { public state: IState = {apps: []}; public componentWillMount() { AppStore.on('change', this.updateApps); } public componentWillUnmount() { AppStore.removeListener('change', this.updateApps); } public render() { const {classes, loggedIn} = this.props; const {apps} = this.state; const userApps = apps.length === 0 ? null : apps.map((app) => { return ( ); }); const placeholderItems = [ , , ]; return (
{loggedIn ? userApps : placeholderItems}
); } private updateApps = () => this.setState({apps: AppStore.get()}); } export default withStyles(styles, {withTheme: true})(Navigation);