-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notification & Service Worker Update (#13)
* changed service worker to use the one that comes with angular * added notificaiton service, and added delete confirmation on edit screen * modified notifications so caller can delete them * Any outstanding messages will be destroyed on component change * made gtag https * Service worker now will ask if you want to update
- Loading branch information
Showing
29 changed files
with
466 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Subject } from 'rxjs/Subject'; | ||
|
||
export class Button { | ||
name: string; | ||
color?: string; | ||
} | ||
|
||
export class Notification { | ||
id?: Symbol; | ||
message: string; | ||
response?: Subject<string>; | ||
buttons?: Button[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { NotificationService } from './notification.service'; | ||
|
||
describe('NotificationService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [NotificationService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([NotificationService], (service: NotificationService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Subject } from 'rxjs/Subject'; | ||
import { Notification } from '../_classes/notification'; | ||
|
||
interface NotificationEvent { | ||
event: 'add' | 'delete'; | ||
notification?: Notification; | ||
id?: Symbol; | ||
} | ||
|
||
@Injectable() | ||
export class NotificationService { | ||
|
||
notifications$ = new Subject<NotificationEvent>(); | ||
|
||
constructor() { } | ||
|
||
add(notification: Notification) { | ||
const response = new Subject<string>(); | ||
notification.id = Symbol(); | ||
notification.response = response; | ||
const event: NotificationEvent = { | ||
event: 'add', | ||
notification: notification | ||
}; | ||
this.notifications$.next(event); | ||
return notification; | ||
} | ||
|
||
delete(id: Symbol) { | ||
const event: NotificationEvent = { | ||
event: 'delete', | ||
id: id | ||
}; | ||
this.notifications$.next(event); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { SwUpdateService } from './sw-update.service'; | ||
|
||
describe('SwUpdateService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [SwUpdateService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([SwUpdateService], (service: SwUpdateService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { NotificationService } from './notification.service'; | ||
import { SwUpdate } from '@angular/service-worker'; | ||
|
||
@Injectable() | ||
export class SwUpdateService { | ||
|
||
constructor(private _notifySvc: NotificationService, updates: SwUpdate) { | ||
updates.available.subscribe(event => { | ||
const updateConfirm = this._notifySvc.add({ | ||
message: 'New Version Available.', | ||
buttons: [ | ||
{ name: 'update' }, | ||
{ name: 'cancel', color: 'red' } | ||
] | ||
}); | ||
updateConfirm.response.subscribe(response => { | ||
if (response === 'update') { | ||
console.log('Updating Application'); | ||
updates.activateUpdate().then(() => location.reload()); | ||
} | ||
}); | ||
}); | ||
updates.activated.subscribe(event => { | ||
console.log('Update Activated', event); | ||
}); | ||
updates.checkForUpdate(); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { SwUpdateService } from './_services/sw-update.service'; | ||
|
||
@Component({ | ||
selector: 'tt-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'] | ||
}) | ||
export class AppComponent { | ||
title = 'Tabletop'; | ||
title = 'Tabletop Helper'; | ||
|
||
constructor(private _appUpdate: SwUpdateService) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.