From ee7f54bb0d873a3e171ff0b121ea96388b2204ee Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 14 Jun 2023 20:06:50 -0400 Subject: [PATCH] Adding window visibility check, removing generic sleep. --- src/shared/components/app/navbar.tsx | 34 +++++++++++++++------------- src/shared/utils.ts | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 6bad5a55..6d310eef 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -410,29 +410,31 @@ export class Navbar extends Component { fetchUnreads() { poll(async () => { - const auth = myAuth(); - if (auth) { - this.setState({ - unreadInboxCountRes: await HttpService.client.getUnreadCount({ - auth, - }), - }); - - if (this.moderatesSomething) { + if (window.document.visibilityState !== "hidden") { + const auth = myAuth(); + if (auth) { this.setState({ - unreadReportCountRes: await HttpService.client.getReportCount({ + unreadInboxCountRes: await HttpService.client.getUnreadCount({ auth, }), }); - } - if (amAdmin()) { - this.setState({ - unreadApplicationCountRes: - await HttpService.client.getUnreadRegistrationApplicationCount({ + if (this.moderatesSomething) { + this.setState({ + unreadReportCountRes: await HttpService.client.getReportCount({ auth, }), - }); + }); + } + + if (amAdmin()) { + this.setState({ + unreadApplicationCountRes: + await HttpService.client.getUnreadRegistrationApplicationCount({ + auth, + }), + }); + } } } }, updateUnreadCountsInterval); diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 7b30390f..5bb9ddcf 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1492,7 +1492,7 @@ export function newVote(voteType: VoteType, myVote?: number): number { } } -function sleep(millis: number): Promise { +function sleep(millis: number): Promise { return new Promise(resolve => setTimeout(resolve, millis)); }