Adding window visibility check, removing generic sleep.

This commit is contained in:
Dessalines 2023-06-14 20:06:50 -04:00
parent caf445cae7
commit ee7f54bb0d
2 changed files with 19 additions and 17 deletions

View file

@ -410,29 +410,31 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
fetchUnreads() { fetchUnreads() {
poll(async () => { poll(async () => {
const auth = myAuth(); if (window.document.visibilityState !== "hidden") {
if (auth) { const auth = myAuth();
this.setState({ if (auth) {
unreadInboxCountRes: await HttpService.client.getUnreadCount({
auth,
}),
});
if (this.moderatesSomething) {
this.setState({ this.setState({
unreadReportCountRes: await HttpService.client.getReportCount({ unreadInboxCountRes: await HttpService.client.getUnreadCount({
auth, auth,
}), }),
}); });
}
if (amAdmin()) { if (this.moderatesSomething) {
this.setState({ this.setState({
unreadApplicationCountRes: unreadReportCountRes: await HttpService.client.getReportCount({
await HttpService.client.getUnreadRegistrationApplicationCount({
auth, auth,
}), }),
}); });
}
if (amAdmin()) {
this.setState({
unreadApplicationCountRes:
await HttpService.client.getUnreadRegistrationApplicationCount({
auth,
}),
});
}
} }
} }
}, updateUnreadCountsInterval); }, updateUnreadCountsInterval);

View file

@ -1492,7 +1492,7 @@ export function newVote(voteType: VoteType, myVote?: number): number {
} }
} }
function sleep<T>(millis: number): Promise<T> { function sleep(millis: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, millis)); return new Promise(resolve => setTimeout(resolve, millis));
} }