You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.5 KiB
TypeScript
114 lines
3.5 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router';
|
||
7 years ago
|
import { List, ListItem, ListSubheader, ListDivider } from '../widgets/List';
|
||
7 years ago
|
import ActionCode from 'material-ui/svg-icons/action/code';
|
||
|
import ActionHome from 'material-ui/svg-icons/action/home';
|
||
|
import ActionBugReport from 'material-ui/svg-icons/action/bug-report';
|
||
|
import ActionQuestionAnswer from 'material-ui/svg-icons/action/question-answer';
|
||
|
import LogoutIcon from 'material-ui/svg-icons/action/power-settings-new';
|
||
|
|
||
7 years ago
|
const logo = require('../images/logo.svg');
|
||
7 years ago
|
|
||
|
import SideMenuJournals from './SideMenuJournals';
|
||
|
|
||
7 years ago
|
import { routeResolver, getPalette } from '../App';
|
||
7 years ago
|
|
||
7 years ago
|
import { store, JournalsType, StoreState, CredentialsData } from '../store';
|
||
|
import { logout } from '../store/actions';
|
||
7 years ago
|
|
||
7 years ago
|
import * as C from '../constants';
|
||
7 years ago
|
|
||
|
interface PropsType {
|
||
|
etesync: CredentialsData | null;
|
||
|
onCloseDrawerRequest: () => void;
|
||
|
}
|
||
|
|
||
|
interface PropsTypeInner extends PropsType {
|
||
|
journals: JournalsType;
|
||
7 years ago
|
history: any;
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
class SideMenu extends React.PureComponent {
|
||
7 years ago
|
props: PropsTypeInner;
|
||
|
|
||
|
constructor(props: any) {
|
||
|
super(props);
|
||
|
this.logout = this.logout.bind(this);
|
||
|
}
|
||
|
|
||
|
logout() {
|
||
|
store.dispatch(logout());
|
||
|
this.props.onCloseDrawerRequest();
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
const username = (this.props.etesync && this.props.etesync.credentials.email) ?
|
||
|
this.props.etesync.credentials.email
|
||
|
: C.appName;
|
||
|
|
||
|
let loggedInItems;
|
||
|
if (this.props.etesync) {
|
||
|
const journals = (this.props.journals && this.props.journals.value) && (
|
||
|
<React.Fragment>
|
||
7 years ago
|
<ListDivider />
|
||
|
<ListSubheader>Journals</ListSubheader>
|
||
7 years ago
|
<SideMenuJournals
|
||
|
etesync={this.props.etesync}
|
||
|
journals={this.props.journals.value}
|
||
7 years ago
|
onItemClick={(journalUid: string) => {
|
||
|
this.props.onCloseDrawerRequest();
|
||
|
this.props.history.push(routeResolver.getRoute('journals._id', { journalUid: journalUid }));
|
||
|
}}
|
||
7 years ago
|
/>
|
||
|
</React.Fragment>
|
||
|
);
|
||
|
|
||
|
loggedInItems = (
|
||
|
<React.Fragment>
|
||
|
<ListItem primaryText="Log Out" leftIcon={<LogoutIcon/>} onClick={this.logout} />
|
||
|
{journals}
|
||
|
</React.Fragment>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<React.Fragment>
|
||
|
<div className="App-drawer-header">
|
||
|
<img className="App-drawer-logo" src={logo} />
|
||
|
<div style={{color: getPalette('alternateTextColor')}} >
|
||
|
{username}
|
||
|
</div>
|
||
|
</div>
|
||
|
<List>
|
||
7 years ago
|
<ListItem
|
||
|
primaryText="Main"
|
||
|
leftIcon={<ActionHome />}
|
||
|
onClick={() => {
|
||
|
this.props.onCloseDrawerRequest();
|
||
|
this.props.history.push(routeResolver.getRoute('home'));
|
||
|
}}
|
||
|
/>
|
||
7 years ago
|
{loggedInItems}
|
||
7 years ago
|
<ListDivider />
|
||
|
<ListSubheader>External Links</ListSubheader>
|
||
7 years ago
|
<ListItem primaryText="Website" leftIcon={<ActionHome />} href={C.homePage} />
|
||
|
<ListItem primaryText="FAQ" leftIcon={<ActionQuestionAnswer />} href={C.faq} />
|
||
|
<ListItem primaryText="Source Code" leftIcon={<ActionCode />} href={C.sourceCode} />
|
||
|
<ListItem primaryText="Report Issue" leftIcon={<ActionBugReport />} href={C.reportIssue} />
|
||
|
</List>
|
||
|
</React.Fragment>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const mapStateToProps = (state: StoreState, props: PropsType) => {
|
||
|
return {
|
||
|
journals: state.cache.journals,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export default withRouter(connect(
|
||
|
mapStateToProps
|
||
|
)(SideMenu));
|