impr: throttle connection state notifications

now the banner/notification will only show once per 10 seconds

closes #4875
This commit is contained in:
Miodec 2023-12-19 14:22:44 +01:00
parent ccdc774e72
commit 6ee981b2f9

View file

@ -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) {