Skip to content
Permalink
Browse files

fix: make redirect timer count down to zero (#37148)

  • Loading branch information...
moT01 authored and raisedadead committed Oct 9, 2019
1 parent 52653c5 commit 8de9cb729b561a81f01f1086e2ecfa97aa6fedb1
Showing with 10 additions and 4 deletions.
  1. +10 −4 client/src/client-only-routes/ShowUser.js
@@ -64,15 +64,16 @@ class ShowUser extends Component {

this.timer = null;
this.state = {
textarea: ''
textarea: '',
time: 5
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

componentWillUnmount() {
if (this.timer) {
clearTimeout(this.timer);
clearInterval(this.timer);
}
}

@@ -92,7 +93,12 @@ class ShowUser extends Component {

setNavigationTimer(navigate) {
if (!this.timer) {
this.timer = setTimeout(() => navigate(`${apiLocation}/signin`), 5000);
this.timer = setInterval(() => {
if (this.state.time <= 0) {
navigate(`${apiLocation}/signin`);
}
this.setState({ time: this.state.time - 1 });
}, 1000);
}
}

@@ -120,7 +126,7 @@ class ShowUser extends Component {
<Spacer />
<p>
You will be redirected to sign in to freeCodeCamp.org
automatically in 5 seconds
automatically in {this.state.time} seconds
</p>
<p>
<Button

0 comments on commit 8de9cb7

Please sign in to comment.
You can’t perform that action at this time.