From e3e1b8f411fdb2e38634eaf75439f5de4fc64019 Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 28 Aug 2017 18:49:47 +0900 Subject: [PATCH] route history back bug fix --- .../app/views/layout/ProbeDetailLayout.tsx | 4 +--- .../app/views/layout/SensorDetailLayout.tsx | 4 +--- .../app/views/layout/TargetDetailLayout.tsx | 6 ++--- .../@overflow/app/views/layout/TitleBar.tsx | 24 ++++++++++++++++--- .../app/views/layout/TitleBarContainer.tsx | 1 + 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx b/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx index 056830b..f25b08a 100644 --- a/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx @@ -15,7 +15,6 @@ import HistoryView from '../../views/history/List'; export interface Props extends RouteComponentProps { } export interface State { - currUrl: string; } export class ProbeDetailLayout extends React.Component { @@ -23,7 +22,6 @@ export class ProbeDetailLayout extends React.Component { constructor(props: Props, context: State) { super(props, context); this.state = { - currUrl: this.props.location.pathname, }; } @@ -52,7 +50,7 @@ export class ProbeDetailLayout extends React.Component {
- + diff --git a/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx b/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx index 5bbfe56..d13b272 100644 --- a/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx @@ -14,7 +14,6 @@ import HistoryView from '../../views/history/List'; export interface Props extends RouteComponentProps { } export interface State { - currUrl: string; } class SensorDetailLayout extends React.Component { @@ -22,7 +21,6 @@ class SensorDetailLayout extends React.Component { public constructor(props?: Props, context?: State) { super(props, context); this.state = { - currUrl: this.props.location.pathname, }; } @@ -50,7 +48,7 @@ class SensorDetailLayout extends React.Component {
- + {/**/} diff --git a/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx b/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx index 57717eb..ca28da9 100644 --- a/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx @@ -13,7 +13,6 @@ import HistoryView from '../../views/history/List'; export interface Props extends RouteComponentProps { } export interface State { - currUrl: string; } export class TargetDetailLayout extends React.Component { @@ -21,7 +20,6 @@ export class TargetDetailLayout extends React.Component { constructor(props: Props, context: State) { super(props, context); this.state = { - currUrl: this.props.location.pathname, }; } @@ -30,7 +28,7 @@ export class TargetDetailLayout extends React.Component { const sub = [ { 'name': 'Info', - 'path': '', + 'path': '/', }, { 'name': 'Sensor', @@ -46,7 +44,7 @@ export class TargetDetailLayout extends React.Component {
- + diff --git a/src/ts/@overflow/app/views/layout/TitleBar.tsx b/src/ts/@overflow/app/views/layout/TitleBar.tsx index 7c5c4cd..d4243d6 100644 --- a/src/ts/@overflow/app/views/layout/TitleBar.tsx +++ b/src/ts/@overflow/app/views/layout/TitleBar.tsx @@ -5,6 +5,7 @@ import { Grid, Container, Breadcrumb, Header, Menu, Input, Segment, Dropdown } f export interface StateProps { sub: any; location: string; + history: any; } export interface DispatchProps { @@ -32,13 +33,30 @@ export class TitleBar extends React.Component { } let last = this.props.location.split('/').pop().toLowerCase(); - for(let i = 0; i < this.props.sub.length; i++) { - if(this.props.sub[i].name.toLowerCase() === last) { - this.setState({selected: i}); + for (let i = 0; i < this.props.sub.length; i++) { + if (this.props.sub[i].name.toLowerCase() === last) { + this.setState({ selected: i }); + return; } } } + public componentWillUpdate(nextProps: Props, nextState: State): void { + if (nextProps !== this.props) { + if (!this.props.history.location.pathname) { + return; + } + let last = this.props.history.location.pathname.split('/').pop().toLowerCase(); + for (let i = 0; i < this.props.sub.length; i++) { + if (this.props.sub[i].name.toLowerCase() === last) { + this.setState({ selected: i }); + return; + } + } + this.setState({ selected: 0 }); + } + } + public handleMenu(menu: any, index: number): any { this.setState({ selected: index, diff --git a/src/ts/@overflow/app/views/layout/TitleBarContainer.tsx b/src/ts/@overflow/app/views/layout/TitleBarContainer.tsx index 27cbb34..33b4e52 100644 --- a/src/ts/@overflow/app/views/layout/TitleBarContainer.tsx +++ b/src/ts/@overflow/app/views/layout/TitleBarContainer.tsx @@ -11,6 +11,7 @@ export function mapStateToProps(state: any, ownProps: any): StateProps { return { sub: ownProps.sub, location: ownProps.location, + history: ownProps.history, }; }