Skip to content

Commit

Permalink
Close #242: added ui indication for offline state
Browse files Browse the repository at this point in the history
  • Loading branch information
Ofer Segev authored and arikfr committed Jan 19, 2017
1 parent ddf6fc5 commit 06186d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ngModule.config(($routeProvider, $locationProvider, $compileProvider,
});

// Update ui-select's template to use Font-Awesome instead of glyphicon.
ngModule.run(($templateCache) => {
ngModule.run(($templateCache, OfflineListener) => { // eslint-disable-line no-unused-vars
const templateName = 'bootstrap/match.tpl.html';
let template = $templateCache.get(templateName);
template = template.replace('glyphicon glyphicon-remove', 'fa fa-remove');
Expand Down
1 change: 1 addition & 0 deletions client/app/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export { default as DataSource } from './data-source';
export { default as QuerySnippet } from './query-snippet';
export { default as Notifications } from './notifications';
export { default as KeyboardShortcuts } from './keyboard-shortcuts';
export { default as OfflineListener } from './offline-listener';
export { default as AlertDialog } from './alert-dialog';
export { default as Auth } from './auth';
23 changes: 23 additions & 0 deletions client/app/services/offline-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function OfflineListener(toastr) {
function addOnlineListener(toast) {
function onlineStateHandler() {
toastr.remove(toast.toastId);
window.removeEventListener('online', onlineStateHandler);
}
window.addEventListener('online', onlineStateHandler);
}

window.addEventListener('offline', () => {
const toast = toastr.warning('<div>Please check your Internet connection.</div>', '', {
allowHtml: true,
autoDismiss: false,
timeOut: false,
tapToDismiss: true,
});
addOnlineListener(toast);
});
}

export default function (ngModule) {
ngModule.service('OfflineListener', OfflineListener);
}

0 comments on commit 06186d9

Please sign in to comment.