commit c0c94b03aa8241260b80faaddeace494e45fd1fd
parent e26018fdd753800b218532e927e1202a6a687333
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 17 Apr 2025 14:01:31 +0200
parent e26018fdd753800b218532e927e1202a6a687333
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 17 Apr 2025 14:01:31 +0200
baseView: add `isOffline` state variable
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/baseView.js b/src/baseView.js @@ -5,6 +5,7 @@ import { baseStyles, helperStyles, flexboxStyles, overlaysStyles, buttonInputSty export class BaseView extends LitElement { static properties = { + isOffline: { state: true }, isUpdating: { state: true }, overlayType: { state: true }, overlayTitle: { state: true }, @@ -24,6 +25,7 @@ export class BaseView extends LitElement { constructor () { super(); + this.isOffline = !navigator.onLine; this.isUpdating = false; this.overlayType = 'plain'; @@ -32,6 +34,20 @@ export class BaseView extends LitElement { this.overlayTitle = null; } + connectedCallback() { + super.connectedCallback(); + window.addEventListener('online', this.connectionHandler); + window.addEventListener('offline', this.connectionHandler); + } + + disconnectedCallback() { + super.disconnectedCallback(); + window.removeEventListener('online', this.connectionHandler); + window.removeEventListener('offline', this.connectionHandler); + } + + connectionHandler = event => { this.isOffline = event.type === 'offline'; }; + showLoaderOverlay = () => this.showOverlay('loader'); showDialogOverlay = (title, body) => this.showOverlay('dialog', body, title); showAlertOverlay = text => this.showOverlay('alert', text);