From b16edfad9e89577d7afd55a25b589d21d1511886 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Tue, 17 Oct 2023 12:30:54 +0300 Subject: [PATCH] feat(notification): add service worker support for `@ng-web-apis/notification` --- apps/demo/src/app/app.browser.module.ts | 4 +- .../examples/01-getting-permission/index.ts | 3 +- .../examples/02-create-notification/index.ts | 5 +- .../examples/03-close-notification/index.html | 1 + .../examples/03-close-notification/index.ts | 18 ++-- .../04-listen-notification-events/index.ts | 10 ++- .../notification-page.component.ts | 5 +- .../notification-page.template.html | 24 ++++- .../payment-request/shop/shop.component.ts | 4 +- libs/common/src/index.ts | 3 + libs/common/src/tokens/service-worker.ts | 9 ++ libs/common/src/types/injection-token-type.ts | 3 + libs/common/src/utils/zone.ts | 24 +++++ libs/notification/src/index.ts | 2 + .../src/services/notification.service.ts | 87 ++++++++++++++++--- .../src/tokens/notification-clicks.ts | 10 +++ .../src/tokens/notification-closes.ts | 11 +++ .../src/tokens/notification-factory.ts | 27 ++++++ .../notification/src/utils/provide-sw-push.ts | 45 ++++++++++ 19 files changed, 262 insertions(+), 33 deletions(-) create mode 100644 libs/common/src/tokens/service-worker.ts create mode 100644 libs/common/src/types/injection-token-type.ts create mode 100644 libs/common/src/utils/zone.ts create mode 100644 libs/notification/src/tokens/notification-clicks.ts create mode 100644 libs/notification/src/tokens/notification-closes.ts create mode 100644 libs/notification/src/tokens/notification-factory.ts create mode 100644 libs/notification/src/utils/provide-sw-push.ts diff --git a/apps/demo/src/app/app.browser.module.ts b/apps/demo/src/app/app.browser.module.ts index 021899e64..56a807b29 100644 --- a/apps/demo/src/app/app.browser.module.ts +++ b/apps/demo/src/app/app.browser.module.ts @@ -2,8 +2,9 @@ import {LocationStrategy, PathLocationStrategy} from '@angular/common'; import {NgModule, SecurityContext} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; -import {ServiceWorkerModule} from '@angular/service-worker'; +import {ServiceWorkerModule, SwPush} from '@angular/service-worker'; import {POSITION_OPTIONS} from '@ng-web-apis/geolocation'; +import {provideSwPush} from '@ng-web-apis/notification'; import {TuiLinkModule, TuiRootModule, TuiSvgModule} from '@taiga-ui/core'; import {HIGHLIGHT_OPTIONS, HighlightModule} from 'ngx-highlightjs'; import {MarkdownModule} from 'ngx-markdown'; @@ -35,6 +36,7 @@ import {AppRoutingModule} from './app.routes'; ], declarations: [AppComponent], providers: [ + provideSwPush(SwPush), { provide: HIGHLIGHT_OPTIONS, useValue: {fullLibraryLoader: async () => import(`highlight.js`)}, diff --git a/apps/demo/src/app/pages/notification/examples/01-getting-permission/index.ts b/apps/demo/src/app/pages/notification/examples/01-getting-permission/index.ts index 6195be330..726663e44 100644 --- a/apps/demo/src/app/pages/notification/examples/01-getting-permission/index.ts +++ b/apps/demo/src/app/pages/notification/examples/01-getting-permission/index.ts @@ -2,12 +2,13 @@ import {CommonModule} from '@angular/common'; import {ChangeDetectionStrategy, Component, inject} from '@angular/core'; import {NotificationService} from '@ng-web-apis/notification'; import {PermissionsService} from '@ng-web-apis/permissions'; +import {TuiButtonModule} from '@taiga-ui/core'; import {TuiBadgeModule} from '@taiga-ui/kit'; @Component({ standalone: true, selector: 'notification-page-example-1', - imports: [CommonModule, TuiBadgeModule], + imports: [CommonModule, TuiBadgeModule, TuiButtonModule], templateUrl: './index.html', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/apps/demo/src/app/pages/notification/examples/02-create-notification/index.ts b/apps/demo/src/app/pages/notification/examples/02-create-notification/index.ts index 116c93dca..1f79d06c9 100644 --- a/apps/demo/src/app/pages/notification/examples/02-create-notification/index.ts +++ b/apps/demo/src/app/pages/notification/examples/02-create-notification/index.ts @@ -1,13 +1,14 @@ -import {CommonModule} from '@angular/common'; +import {AsyncPipe} from '@angular/common'; import {ChangeDetectionStrategy, Component, inject} from '@angular/core'; import {NotificationService} from '@ng-web-apis/notification'; import {isDenied, isGranted, PermissionsService} from '@ng-web-apis/permissions'; +import {TuiButtonModule} from '@taiga-ui/core'; import {filter, map, switchMap} from 'rxjs/operators'; @Component({ standalone: true, selector: 'notification-page-example-2', - imports: [CommonModule], + imports: [AsyncPipe, TuiButtonModule], templateUrl: './index.html', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/apps/demo/src/app/pages/notification/examples/03-close-notification/index.html b/apps/demo/src/app/pages/notification/examples/03-close-notification/index.html index e46c535c9..e993760a3 100644 --- a/apps/demo/src/app/pages/notification/examples/03-close-notification/index.html +++ b/apps/demo/src/app/pages/notification/examples/03-close-notification/index.html @@ -1,6 +1,7 @@