Mercurial > hg > ugly-duckling
changeset 493:7f9fb84816b9
Introduce a singleton / service for communicating errors / or other notifications (there aren't any yet) - using MdSnackBar internally.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Thu, 06 Jul 2017 19:47:18 +0100 |
parents | 023fbba200d2 |
children | f52eb1b422f5 |
files | src/app/app.module.ts src/app/services/notifications/notifications.service.ts src/app/ugly-material.module.ts |
diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/app.module.ts Thu Jul 06 12:52:24 2017 +0100 +++ b/src/app/app.module.ts Thu Jul 06 19:47:18 2017 +0100 @@ -42,6 +42,7 @@ ActionTrayComponent } from './actions/action-tray.component'; import {RecordRtcMediaRecorder} from './services/audio-recorder/RecordRtcMediaRecorder'; +import {NotificationService} from './services/notifications/notifications.service'; export function createAudioContext(): AudioContext { return new ( @@ -163,7 +164,8 @@ {provide: 'UrlResourceLifetimeManager', useFactory: createUrlResourceManager}, {provide: 'ResourceReader', useFactory: createResourceReader}, {provide: 'DimensionObservable', useFactory: createWindowDimensionObservable}, - RenderLoopService + RenderLoopService, + NotificationService ], bootstrap: [AppComponent] })
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app/services/notifications/notifications.service.ts Thu Jul 06 19:47:18 2017 +0100 @@ -0,0 +1,18 @@ +/** + * Created by lucast on 06/07/2017. + */ +import {Injectable} from '@angular/core'; +import {MdSnackBar} from '@angular/material'; +@Injectable() +export class NotificationService { + constructor(private snackBar: MdSnackBar) {} + + displayError(message: string): void { + // TODO perhaps actual distinguish this as an error? + this.displayMessage(message); + } + + private displayMessage(message: string): void { + this.snackBar.open(message, 'Dismiss', {duration: 5000}); + }; +}
--- a/src/app/ugly-material.module.ts Thu Jul 06 12:52:24 2017 +0100 +++ b/src/app/ugly-material.module.ts Thu Jul 06 19:47:18 2017 +0100 @@ -5,7 +5,7 @@ MdButtonModule, MdCardModule, MdIconModule, MdListModule, MdProgressBarModule, MdProgressSpinnerModule, MdSelectModule, - MdSidenavModule, + MdSidenavModule, MdSnackBarModule, MdToolbarModule } from '@angular/material'; import {NgModule} from '@angular/core'; @@ -21,7 +21,8 @@ MdProgressSpinnerModule, MdProgressBarModule, MdCardModule, - MdListModule + MdListModule, + MdSnackBarModule ]; @NgModule({