From 8de9cb729b561a81f01f1086e2ecfa97aa6fedb1 Mon Sep 17 00:00:00 2001
From: Tom <20648924+moT01@users.noreply.github.com>
Date: Wed, 9 Oct 2019 08:58:49 -0500
Subject: [PATCH] fix: make redirect timer count down to zero (#37148)
---
client/src/client-only-routes/ShowUser.js | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/client/src/client-only-routes/ShowUser.js b/client/src/client-only-routes/ShowUser.js
index cee81766aa..12635ecf03 100644
--- a/client/src/client-only-routes/ShowUser.js
+++ b/client/src/client-only-routes/ShowUser.js
@@ -64,7 +64,8 @@ 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);
@@ -72,7 +73,7 @@ class ShowUser extends Component {
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 {
You will be redirected to sign in to freeCodeCamp.org - automatically in 5 seconds + automatically in {this.state.time} seconds