Skip to content

Commit

Permalink
URL Changes (dexlab-io#78)
Browse files Browse the repository at this point in the history
* Created a new method of the Dashboard component, which changes the
  URL of the current page according to the active tab
* Called the new method from the tab change handlers for desktop and mobile
  • Loading branch information
Emilio Silva Schlenker committed Mar 14, 2019
1 parent e8579a3 commit 1c828d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/pages/Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ class Dashboard extends Component {
this.confetti();
}

setUrl = nextTab => {
if (nextTab === 'tip') {
window.history.replaceState({}, '', '/address/' + this.state.pos.address + '/tip');
}
else {
window.history.replaceState({}, '', '/address/' + this.state.pos.address);
}
}

handleNavItemChange = activeTab => {
// eslint-disable-next-line
const currentTab = this.state.activeTab;
Expand All @@ -100,8 +109,14 @@ class Dashboard extends Component {
this.setState({ totalAmount: '0' });
}
this.setState({ activeTab, lastTab: currentTab });
this.setUrl(nextTab);
};

handleTabChange = nextTab => {
this.setState({ activeTab: nextTab });
this.setUrl(nextTab);
}

onCloseTip = () => {
this.handleNavItemChange(this.state.lastTab);
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard/mobile.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function() {
<div className="container is-fluid">
<NavTabs
activeTab={activeTab}
onChange={tab => this.setState({ activeTab: tab })}
onChange={this.handleTabChange}
/>
{pos.address ? (
<div>
Expand Down

0 comments on commit 1c828d6

Please sign in to comment.