Skip to content

Commit 1db821f

Browse files
committed
show notification when offline
1 parent 776e731 commit 1db821f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { UmbAppContextConfig } from './app-context-config.interface.js';
2+
import { UmbNetworkConnectionStatusManager } from './network-connection-status.manager.js';
23
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
34
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
45
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
@@ -13,6 +14,8 @@ export class UmbAppContext extends UmbContextBase<UmbAppContext> {
1314
this.#serverUrl = config.serverUrl;
1415
this.#backofficePath = config.backofficePath;
1516
this.#serverConnection = config.serverConnection;
17+
18+
new UmbNetworkConnectionStatusManager(this);
1619
}
1720

1821
getBackofficePath() {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
2+
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
3+
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
4+
import {
5+
UMB_NOTIFICATION_CONTEXT,
6+
type UmbNotificationContext,
7+
type UmbNotificationHandler,
8+
} from '@umbraco-cms/backoffice/notification';
9+
10+
export class UmbNetworkConnectionStatusManager extends UmbControllerBase {
11+
#notificationContext?: UmbNotificationContext;
12+
#offlineNotification?: UmbNotificationHandler;
13+
14+
#localize = new UmbLocalizationController(this);
15+
16+
constructor(host: UmbControllerHost) {
17+
super(host);
18+
19+
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
20+
this.#notificationContext = notificationContext;
21+
});
22+
23+
window.addEventListener('online', () => this.#onOnline());
24+
window.addEventListener('offline', () => this.#onOffline());
25+
}
26+
27+
#onOnline() {
28+
this.#offlineNotification?.close();
29+
}
30+
31+
#onOffline() {
32+
this.#offlineNotification = this.#notificationContext?.stay('danger', {
33+
data: {
34+
headline: this.#localize.term('speechBubbles_offlineHeadline'),
35+
message: this.#localize.term('speechBubbles_offlineMessage'),
36+
},
37+
});
38+
}
39+
40+
override destroy() {
41+
this.#offlineNotification?.close();
42+
this.removeEventListener('online', () => this.#onOnline());
43+
this.removeEventListener('offline', () => this.#onOffline());
44+
super.destroy();
45+
}
46+
}

src/Umbraco.Web.UI.Client/src/assets/lang/en-us.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,8 @@ export default {
14881488
preventCleanupDisableError: 'An error occurred while disabling version cleanup for %0%',
14891489
copySuccessMessage: 'Your system information has successfully been copied to the clipboard',
14901490
cannotCopyInformation: 'Could not copy your system information to the clipboard',
1491+
offlineHeadline: 'Offline',
1492+
offlineMessage: 'You are currently offline. Please check your internet connection.',
14911493
},
14921494
stylesheet: {
14931495
addRule: 'Add style',

0 commit comments

Comments
 (0)