import * as React from 'react'; import { connect } from 'react-redux'; import { RouteComponentProps, withRouter } from 'react-router'; import { List, ListItem, ListSubheader, ListDivider } from '../widgets/List'; import { Theme, withTheme } from '@material-ui/core/styles'; import ActionCode from '@material-ui/icons/Code'; import ActionHome from '@material-ui/icons/Home'; import ActionSettings from '@material-ui/icons/Settings'; import ActionJournals from '@material-ui/icons/LibraryBooks'; import ActionBugReport from '@material-ui/icons/BugReport'; import ActionQuestionAnswer from '@material-ui/icons/QuestionAnswer'; import LogoutIcon from '@material-ui/icons/PowerSettingsNew'; import IconImport from '@material-ui/icons/ImportExport'; import logo from '../images/logo.svg'; import { routeResolver } from '../App'; import { store, JournalsType, UserInfoData, StoreState, CredentialsData } from '../store'; import { logout } from '../store/actions'; import * as C from '../constants'; interface PropsType { etesync: CredentialsData | null; onCloseDrawerRequest: () => void; } type PropsTypeInner = RouteComponentProps<{}> & PropsType & { journals: JournalsType; userInfo: UserInfoData; theme: Theme; }; class SideMenu extends React.PureComponent { constructor(props: PropsTypeInner) { super(props); this.logout = this.logout.bind(this); } public logout() { store.dispatch(logout(this.props.etesync!)); this.props.onCloseDrawerRequest(); } public render() { const { theme } = this.props; const username = (this.props.etesync && this.props.etesync.credentials.email) ? this.props.etesync.credentials.email : C.appName; let loggedInItems; if (this.props.etesync) { loggedInItems = ( } onClick={() => { this.props.onCloseDrawerRequest(); this.props.history.push(routeResolver.getRoute('journals')); }} /> } onClick={() => { this.props.onCloseDrawerRequest(); this.props.history.push(routeResolver.getRoute('journals.import')); }} /> } onClick={() => { this.props.onCloseDrawerRequest(); this.props.history.push(routeResolver.getRoute('settings')); }} /> } onClick={this.logout} /> ); } return (
App logo
{username}
} onClick={() => { this.props.onCloseDrawerRequest(); this.props.history.push(routeResolver.getRoute('home')); }} /> {loggedInItems} External Links } href={C.homePage} /> } href={C.faq} /> } href={C.sourceCode} /> } href={C.reportIssue} />
); } } const mapStateToProps = (state: StoreState, _props: PropsType) => { return { journals: state.cache.journals, userInfo: state.cache.userInfo, }; }; export default withTheme(withRouter(connect( mapStateToProps )(SideMenu)));