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() {
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);

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));
}