web: prevent status update loop in background

When leaving the status page while it is waiting for status data,
the callback happens when the status page is not mounted,
resulting in the update loop timer not being cleared.

This change prevents that by setting the visible attribute to false
when leaving the page, so that the update is not scheduled when
the page is not visible.

Change-Id: I9f3db68bb77c52d0f477b8322bbf52bd3cc81fe1
This commit is contained in:
Tristan Cacqueray 2019-02-12 14:10:32 +00:00
parent 6d6c69f93e
commit 00f4de3c51
1 changed files with 2 additions and 1 deletions

View File

@ -84,7 +84,7 @@ class StatusPage extends Refreshable {
updateData = (force) => {
if (force || (this.visible && this.state.autoReload)) {
this.props.dispatch(fetchStatusIfNeeded(this.props.tenant))
.then(() => {if (this.state.autoReload) {
.then(() => {if (this.state.autoReload && this.visible) {
this.timer = setTimeout(this.updateData, 5000)
}})
}
@ -106,6 +106,7 @@ class StatusPage extends Refreshable {
clearTimeout(this.timer)
this.timer = null
}
this.visible = false
document.removeEventListener(
this.visibilityChangeEvent, this.visibilityListener)
}