Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: UI indication for offline state #1534

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}