Skip to content

Commit c1f74f4

Browse files
authored
Merge pull request #18094 from umbraco/v15/bugfix/offline-notifcation
Bugfix: show notification when offline
2 parents 22d974e + 675e9ab commit c1f74f4

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
this.#notificationContext?.peek('positive', {
30+
data: {
31+
headline: this.#localize.term('speechBubbles_onlineHeadline'),
32+
message: this.#localize.term('speechBubbles_onlineMessage'),
33+
},
34+
});
35+
}
36+
37+
#onOffline() {
38+
this.#offlineNotification = this.#notificationContext?.stay('danger', {
39+
data: {
40+
headline: this.#localize.term('speechBubbles_offlineHeadline'),
41+
message: this.#localize.term('speechBubbles_offlineMessage'),
42+
},
43+
});
44+
}
45+
46+
override destroy() {
47+
this.#offlineNotification?.close();
48+
this.removeEventListener('online', () => this.#onOnline());
49+
this.removeEventListener('offline', () => this.#onOffline());
50+
super.destroy();
51+
}
52+
}

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
@@ -1492,6 +1492,8 @@ export default {
14921492
preventCleanupDisableError: 'An error occurred while disabling version cleanup for %0%',
14931493
copySuccessMessage: 'Your system information has successfully been copied to the clipboard',
14941494
cannotCopyInformation: 'Could not copy your system information to the clipboard',
1495+
offlineHeadline: 'Offline',
1496+
offlineMessage: 'You are currently offline. Please check your internet connection.',
14951497
},
14961498
stylesheet: {
14971499
addRule: 'Add style',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,10 @@ export default {
14961496
scheduleErrExpireDate2: 'The expire date cannot be before the release date',
14971497
preventCleanupEnableError: 'An error occurred while enabling version cleanup for %0%',
14981498
preventCleanupDisableError: 'An error occurred while disabling version cleanup for %0%',
1499+
offlineHeadline: 'Offline',
1500+
offlineMessage: 'You are currently offline. Please check your internet connection.',
1501+
onlineHeadline: 'Online',
1502+
onlineMessage: 'You are now online. You can continue working.',
14991503
},
15001504
stylesheet: {
15011505
addRule: 'Add style',

0 commit comments

Comments
 (0)