Skip to content

Commit 06186d9

Browse files
Ofer Segevarikfr
Ofer Segev
authored andcommitted
Close #242: added ui indication for offline state
1 parent ddf6fc5 commit 06186d9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

client/app/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ngModule.config(($routeProvider, $locationProvider, $compileProvider,
107107
});
108108

109109
// Update ui-select's template to use Font-Awesome instead of glyphicon.
110-
ngModule.run(($templateCache) => {
110+
ngModule.run(($templateCache, OfflineListener) => { // eslint-disable-line no-unused-vars
111111
const templateName = 'bootstrap/match.tpl.html';
112112
let template = $templateCache.get(templateName);
113113
template = template.replace('glyphicon glyphicon-remove', 'fa fa-remove');

client/app/services/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export { default as DataSource } from './data-source';
1212
export { default as QuerySnippet } from './query-snippet';
1313
export { default as Notifications } from './notifications';
1414
export { default as KeyboardShortcuts } from './keyboard-shortcuts';
15+
export { default as OfflineListener } from './offline-listener';
1516
export { default as AlertDialog } from './alert-dialog';
1617
export { default as Auth } from './auth';
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function OfflineListener(toastr) {
2+
function addOnlineListener(toast) {
3+
function onlineStateHandler() {
4+
toastr.remove(toast.toastId);
5+
window.removeEventListener('online', onlineStateHandler);
6+
}
7+
window.addEventListener('online', onlineStateHandler);
8+
}
9+
10+
window.addEventListener('offline', () => {
11+
const toast = toastr.warning('<div>Please check your Internet connection.</div>', '', {
12+
allowHtml: true,
13+
autoDismiss: false,
14+
timeOut: false,
15+
tapToDismiss: true,
16+
});
17+
addOnlineListener(toast);
18+
});
19+
}
20+
21+
export default function (ngModule) {
22+
ngModule.service('OfflineListener', OfflineListener);
23+
}

0 commit comments

Comments
 (0)