Skip to content

Commit

Permalink
fix: make redirect timer count down to zero (#37148)
Browse files Browse the repository at this point in the history
  • Loading branch information
moT01 authored and raisedadead committed Oct 9, 2019
1 parent 52653c5 commit 8de9cb7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/src/client-only-routes/ShowUser.js
Expand Up @@ -64,15 +64,16 @@ class ShowUser extends Component {


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


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


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


setNavigationTimer(navigate) { setNavigationTimer(navigate) {
if (!this.timer) { 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);
} }
} }


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

0 comments on commit 8de9cb7

Please sign in to comment.