mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
impr: throttle connection state notifications
now the banner/notification will only show once per 10 seconds closes #4875
This commit is contained in:
parent
ccdc774e72
commit
6ee981b2f9
|
@ -1,3 +1,4 @@
|
|||
import { throttle } from "throttle-debounce";
|
||||
import * as Notifications from "../elements/notifications";
|
||||
import * as ConnectionEvent from "../observables/connection-event";
|
||||
import * as TestState from "../test/test-state";
|
||||
|
@ -28,8 +29,7 @@ export function showOfflineBanner(): void {
|
|||
}
|
||||
}
|
||||
|
||||
ConnectionEvent.subscribe((newState) => {
|
||||
state = newState;
|
||||
const throttledHandleState = throttle(10000, () => {
|
||||
if (state) {
|
||||
Notifications.add("You're back online", 1, {
|
||||
customTitle: "Connection",
|
||||
|
@ -45,6 +45,11 @@ ConnectionEvent.subscribe((newState) => {
|
|||
}
|
||||
});
|
||||
|
||||
ConnectionEvent.subscribe((newState) => {
|
||||
state = newState;
|
||||
throttledHandleState();
|
||||
});
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
state = navigator.onLine;
|
||||
if (!state) {
|
||||
|
|
Loading…
Reference in a new issue