From 054caaa56ff24e534c7935bf93df8feaa2c732c3 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 17 Dec 2017 13:07:17 +0000 Subject: [PATCH] Change the menu button to a back button on the main page. --- src/App.tsx | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d51c85f..591e487 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { connect } from 'react-redux'; +import { withRouter } from 'react-router'; import { BrowserRouter } from 'react-router-dom'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; @@ -9,6 +10,7 @@ import Drawer from 'material-ui/Drawer'; import IconButton from 'material-ui/IconButton'; import NavigationMenu from 'material-ui/svg-icons/navigation/menu'; +import NavigationBack from 'material-ui/svg-icons/navigation/arrow-back'; import './App.css'; @@ -19,6 +21,8 @@ import { RouteResolver } from './routes'; import * as C from './constants'; import * as store from './store'; +import { History } from 'history'; + const muiTheme = getMuiTheme({ palette: { primary1Color: amber500, @@ -73,6 +77,49 @@ export const routeResolver = new RouteResolver({ }, }); +const AppBarWitHistory = withRouter( + class extends React.PureComponent { + props: { + title: string, + toggleDrawerIcon: any, + history?: History; + staticContext?: any; + }; + + constructor(props: any) { + super(props); + this.goBack = this.goBack.bind(this); + this.canGoBack = this.canGoBack.bind(this); + } + + canGoBack() { + return this.props.history!.location.pathname !== routeResolver.getRoute('pim'); + } + + goBack() { + this.props.history!.goBack(); + } + + render() { + const { + staticContext, + toggleDrawerIcon, + history, + ...props + } = this.props; + return ( + + } + {...props} + /> + ); + } + } +); + class App extends React.PureComponent { state: { drawerOpen: boolean, @@ -105,9 +152,10 @@ class App extends React.PureComponent {
- } + toggleDrawerIcon={} + />