Skip to content

Commit 1c828d6

Browse files
author
Emilio Silva Schlenker
committed
URL Changes (dexlab-io#78)
* 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
1 parent e8579a3 commit 1c828d6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/pages/Dashboard/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ class Dashboard extends Component {
8989
this.confetti();
9090
}
9191

92+
setUrl = nextTab => {
93+
if (nextTab === 'tip') {
94+
window.history.replaceState({}, '', '/address/' + this.state.pos.address + '/tip');
95+
}
96+
else {
97+
window.history.replaceState({}, '', '/address/' + this.state.pos.address);
98+
}
99+
}
100+
92101
handleNavItemChange = activeTab => {
93102
// eslint-disable-next-line
94103
const currentTab = this.state.activeTab;
@@ -100,8 +109,14 @@ class Dashboard extends Component {
100109
this.setState({ totalAmount: '0' });
101110
}
102111
this.setState({ activeTab, lastTab: currentTab });
112+
this.setUrl(nextTab);
103113
};
104114

115+
handleTabChange = nextTab => {
116+
this.setState({ activeTab: nextTab });
117+
this.setUrl(nextTab);
118+
}
119+
105120
onCloseTip = () => {
106121
this.handleNavItemChange(this.state.lastTab);
107122
};

src/pages/Dashboard/mobile.view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function() {
2121
<div className="container is-fluid">
2222
<NavTabs
2323
activeTab={activeTab}
24-
onChange={tab => this.setState({ activeTab: tab })}
24+
onChange={this.handleTabChange}
2525
/>
2626
{pos.address ? (
2727
<div>

0 commit comments

Comments
 (0)