Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI: Hotfix for offline page showing up during reload (#1098)

Martin Peeters201cc15451a2
diff --git a/ui/component/core/src/event.ts b/ui/component/core/src/event.ts
index 14c580972..013efd501 100644
--- a/ui/component/core/src/event.ts
+++ b/ui/component/core/src/event.ts
@@ -96,6 +96,7 @@ abstract class EventProviderImpl implements EventProvider {
protected _assetEventCallbackMap: Map<string, (e: AssetEvent) => void> = new Map();
protected _attributeEventPromise?: Promise<string>;
protected _attributeEventCallbackMap: Map<string, (e: AttributeEvent) => void> = new Map();
+ protected _unloading = false;
protected static _subscriptionCounter: number = 0;
abstract get endpointUrl(): string;
@@ -508,9 +509,11 @@ abstract class EventProviderImpl implements EventProvider {
console.debug("Event provider status changed: " + status);
this._status = status;
- window.setTimeout(() => {
- this._statusCallbacks.forEach((cb) => cb(status));
- }, 0);
+ if(!this._unloading) {
+ window.setTimeout(() => {
+ this._statusCallbacks.forEach((cb) => cb(status));
+ }, 0);
+ }
}
protected _onMessageReceived(subscriptionId: string, event: SharedEvent) {
@@ -609,6 +612,7 @@ export class WebSocketEventProvider extends EventProviderImpl {
// Close socket on unload/refresh of page
window.addEventListener("beforeunload", () => {
+ this._unloading = true;
this.disconnect();
});
}
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.ts
index 3c6815b6b..fbdcea1a1 100644
--- a/ui/component/or-app/src/index.ts
+++ b/ui/component/or-app/src/index.ts
@@ -294,7 +294,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
const pageProvider = this.appConfig!.pages.find((page) => page.name === this._page);
const showOfflineFallback = (this._offline && !pageProvider?.allowOffline);
- const offlinePage = this._mainElem.querySelector('page-offline');
+ const offlinePage = this._mainElem.querySelector('#offline-page');
// If page has changed, replace the previous content with the new page.
// However, if no page is present yet, append it to the page.
@@ -314,6 +314,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
// CASE: "Offline overlay page is present, but should not be shown"
if(offlinePage && !showOfflineFallback) {
+ console.log("Removing offline page fallback!");
this._mainElem.removeChild(offlinePage);
const elem = this._mainElem.firstElementChild as HTMLElement;
@@ -327,8 +328,10 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
// CASE: "Offline overlay page is NOT present, but needs to be there"
else if(!offlinePage && showOfflineFallback) {
+ console.log("Showing offline page fallback!");
const newOfflinePage = (this.appConfig?.offlinePage) ? this.appConfig.offlinePage.pageCreator() : pageOfflineProvider(this._store).pageCreator();
(this._mainElem.firstElementChild as HTMLElement)?.style.setProperty('display', 'none'); // Hide the current page (to the background)
+ newOfflinePage.id = "offline-page";
this._mainElem.appendChild(newOfflinePage);
}
}
@@ -410,8 +413,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
if(!this._offline) {
this._store.dispatch((setOffline(true)))
}
- }
- if(event === OREvent.ONLINE) {
+ } else if(event === OREvent.ONLINE) {
if(this._offline) {
this._store.dispatch((setOffline(false)))
}