minor clean up in notification service and component

This commit is contained in:
Seyi Adebajo 2018-05-21 11:04:46 -07:00
parent ff8897f1a5
commit 4cf03ed9e2
2 changed files with 48 additions and 44 deletions

View File

@ -1,5 +1 @@
import Ember from 'ember'; export { default } from '@ember/component';
const { Component } = Ember;
export default Component.extend({});

View File

@ -1,6 +1,7 @@
import Service from '@ember/service'; import Service from '@ember/service';
import { setProperties, get, set } from '@ember/object'; import { setProperties, get, set } from '@ember/object';
import { delay } from 'wherehows-web/utils/promise-delay'; import { delay } from 'wherehows-web/utils/promise-delay';
import { action } from '@ember-decorators/object';
/** /**
* Flag indicating the current notification queue is being processed * Flag indicating the current notification queue is being processed
@ -8,8 +9,6 @@ import { delay } from 'wherehows-web/utils/promise-delay';
*/ */
let isBuffering = false; let isBuffering = false;
// type NotificationEvent = 'success' | 'error' | 'info' | 'confirm';
/** /**
* String literal of available notifications * String literal of available notifications
*/ */
@ -73,7 +72,7 @@ interface INotification {
/** /**
* Describes the notification resolver interface used in handling the * Describes the notification resolver interface used in handling the
* dequeueing of the notification buffer * de-queueing of the notification buffer
*/ */
interface INotificationResolver { interface INotificationResolver {
queueAwaiter: Promise<void>; queueAwaiter: Promise<void>;
@ -275,7 +274,7 @@ export default class Notifications extends Service {
await toastDelay; await toastDelay;
// Burn toast // Burn toast
if (!(this.isDestroying || this.isDestroying)) { if (!(this.isDestroying || this.isDestroying)) {
this.actions.dismissToast.call(this); this.dismissToast.call(this);
} }
} }
} }
@ -296,41 +295,50 @@ export default class Notifications extends Service {
return enqueue(proxiedNotifications[type](...params), notificationsQueue); return enqueue(proxiedNotifications[type](...params), notificationsQueue);
} }
actions = { /**
/** * Removes the current toast from view and invokes the notification resolution resolver
* Removes the current toast from view and invokes the notification resolution resolver */
*/ @action
dismissToast(this: Notifications) { dismissToast(this: Notifications) {
const { notificationResolution: { onComplete } }: INotification = get(this, 'toast'); const {
set(this, 'isShowingToast', false); notificationResolution: { onComplete }
}: INotification = get(this, 'toast');
set(this, 'isShowingToast', false);
onComplete && onComplete();
}
/**
* Ignores the modal, invokes the user supplied didDismiss callback
*/
@action
dismissModal(this: Notifications) {
const {
props,
notificationResolution: { onComplete }
}: INotification = get(this, 'modal');
if ((<IConfirmOptions>props).dialogActions) {
const { didDismiss } = (<IConfirmOptions>props).dialogActions;
set(this, 'isShowingModal', false);
didDismiss();
onComplete && onComplete(); onComplete && onComplete();
},
/**
* Ignores the modal, invokes the user supplied didDismiss callback
*/
dismissModal(this: Notifications) {
const { props, notificationResolution: { onComplete } }: INotification = get(this, 'modal');
if ((<IConfirmOptions>props).dialogActions) {
const { didDismiss } = (<IConfirmOptions>props).dialogActions;
set(this, 'isShowingModal', false);
didDismiss();
onComplete && onComplete();
}
},
/**
* Confirms the dialog and invokes the user supplied didConfirm callback
*/
confirmModal(this: Notifications) {
const { props, notificationResolution: { onComplete } }: INotification = get(this, 'modal');
if ((<IConfirmOptions>props).dialogActions) {
const { didConfirm } = (<IConfirmOptions>props).dialogActions;
set(this, 'isShowingModal', false);
didConfirm();
onComplete && onComplete();
}
} }
}; }
/**
* Confirms the dialog and invokes the user supplied didConfirm callback
*/
@action
confirmModal(this: Notifications) {
const {
props,
notificationResolution: { onComplete }
}: INotification = get(this, 'modal');
if ((<IConfirmOptions>props).dialogActions) {
const { didConfirm } = (<IConfirmOptions>props).dialogActions;
set(this, 'isShowingModal', false);
didConfirm();
onComplete && onComplete();
}
}
} }