-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
@ng-web-apis/notification
package (Notification API) (#123)
- Loading branch information
1 parent
8bc8eca
commit b2bdc30
Showing
38 changed files
with
1,074 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ jobs: | |
storage, | ||
workers, | ||
view-transition, | ||
notification, | ||
] | ||
name: ${{ matrix.project }} | ||
steps: | ||
|
@@ -128,6 +129,11 @@ jobs: | |
directory: ./coverage/view-transition/ | ||
flags: summary,view-transition | ||
name: view-transition | ||
- uses: codecov/[email protected] | ||
with: | ||
directory: ./coverage/notification/ | ||
flags: summary,notification | ||
name: notification | ||
|
||
concurrency: | ||
group: test-${{ github.workflow }}-${{ github.ref }} | ||
|
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 |
---|---|---|
|
@@ -44,3 +44,4 @@ testem.log | |
Thumbs.db | ||
|
||
apps/demo/routesFile.txt | ||
.ssl |
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
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
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
17 changes: 17 additions & 0 deletions
17
apps/demo/src/app/pages/notification/examples/01-getting-permission/index.html
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,17 @@ | ||
<ng-container [ngSwitch]="notificationPermissionState$ | async"> | ||
<tui-badge | ||
*ngSwitchCase="'granted'" | ||
status="success" | ||
value="Permission is granted" | ||
></tui-badge> | ||
|
||
<tui-badge | ||
*ngSwitchCase="'denied'" | ||
status="error" | ||
value="Permission is denied" | ||
></tui-badge> | ||
|
||
<button *ngSwitchDefault tuiButton (click)="requestPermission()"> | ||
Request permission | ||
</button> | ||
</ng-container> |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/examples/01-getting-permission/index.ts
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,30 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {PermissionsService} from '@ng-web-apis/permissions'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-1', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample1 { | ||
readonly notificationPermissionState$ = this.permissions.state('notifications'); | ||
|
||
constructor( | ||
private readonly notifications: NotificationService, | ||
private readonly permissions: PermissionsService, | ||
) {} | ||
|
||
requestPermission(): void { | ||
this.notifications.requestPermission().subscribe({ | ||
next: permission => | ||
console.info( | ||
'Permission status:', | ||
permission, // 'denied' | 'granted' | ||
), | ||
error: err => | ||
// e.g. 'Notification API is not supported in your browser' | ||
console.error(err), | ||
}); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/demo/src/app/pages/notification/examples/02-create-notification/index.html
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,3 @@ | ||
<button tuiButton [disabled]="(denied$ | async)!" (click)="sendNotification()"> | ||
Send notification | ||
</button> |
33 changes: 33 additions & 0 deletions
33
apps/demo/src/app/pages/notification/examples/02-create-notification/index.ts
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,33 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {isDenied, isGranted, PermissionsService} from '@ng-web-apis/permissions'; | ||
import {filter, map, switchMap} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-2', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample2 { | ||
readonly denied$ = this.permissions.state('notifications').pipe(map(isDenied)); | ||
|
||
constructor( | ||
private readonly notifications: NotificationService, | ||
private readonly permissions: PermissionsService, | ||
) {} | ||
|
||
sendNotification(): void { | ||
this.notifications | ||
.requestPermission() | ||
.pipe( | ||
filter(isGranted), | ||
switchMap(() => | ||
this.notifications.open('Web APIs for Angular', { | ||
body: 'High quality lightweight wrappers for native Web APIs for idiomatic use with Angular', | ||
icon: 'assets/images/web-api.svg', | ||
}), | ||
), | ||
) | ||
.subscribe(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/demo/src/app/pages/notification/examples/03-close-notification/index.html
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,3 @@ | ||
<button tuiButton [disabled]="(denied$ | async)!" (click)="sendNotification()"> | ||
Send notification | ||
</button> |
36 changes: 36 additions & 0 deletions
36
apps/demo/src/app/pages/notification/examples/03-close-notification/index.ts
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,36 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {isDenied, isGranted, PermissionsService} from '@ng-web-apis/permissions'; | ||
import {timer} from 'rxjs'; | ||
import {filter, map, switchMap, takeUntil} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-3', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample3 { | ||
readonly denied$ = this.permissions.state('notifications').pipe(map(isDenied)); | ||
|
||
constructor( | ||
private readonly notifications: NotificationService, | ||
private readonly permissions: PermissionsService, | ||
) {} | ||
|
||
sendNotification(): void { | ||
this.notifications | ||
.requestPermission() | ||
.pipe( | ||
filter(isGranted), | ||
switchMap(() => | ||
this.notifications.open('Close me, please!', { | ||
requireInteraction: true, | ||
}), | ||
), | ||
takeUntil(timer(5_000)), // close stream after 5 seconds | ||
) | ||
.subscribe({ | ||
complete: () => console.info('Notification closed!'), | ||
}); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/demo/src/app/pages/notification/examples/04-listen-notification-events/index.html
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,3 @@ | ||
<button tuiButton [disabled]="(denied$ | async)!" (click)="sendNotification()"> | ||
Send notification | ||
</button> |
36 changes: 36 additions & 0 deletions
36
apps/demo/src/app/pages/notification/examples/04-listen-notification-events/index.ts
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,36 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {NotificationService} from '@ng-web-apis/notification'; | ||
import {isDenied, isGranted, PermissionsService} from '@ng-web-apis/permissions'; | ||
import {fromEvent} from 'rxjs'; | ||
import {filter, map, switchMap} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'notification-page-example-4', | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageExample4 { | ||
readonly denied$ = this.permissions.state('notifications').pipe(map(isDenied)); | ||
|
||
constructor( | ||
private readonly notifications: NotificationService, | ||
private readonly permissions: PermissionsService, | ||
) {} | ||
|
||
sendNotification(): void { | ||
this.notifications | ||
.requestPermission() | ||
.pipe( | ||
filter(isGranted), | ||
switchMap(() => | ||
this.notifications.open(`Click me, please`, { | ||
body: `Then open console and investigate property "target"`, | ||
requireInteraction: true, | ||
data: `Randomly generated number: ${Math.random().toFixed(2)}`, | ||
}), | ||
), | ||
switchMap(notification => fromEvent(notification, 'click')), | ||
) | ||
.subscribe(console.info); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
apps/demo/src/app/pages/notification/notification-page.component.ts
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 {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {PermissionsService} from '@ng-web-apis/permissions'; | ||
import {TuiDocExample} from '@taiga-ui/addon-doc'; | ||
|
||
@Component({ | ||
selector: 'notification-page', | ||
templateUrl: './notification-page.template.html', | ||
styleUrls: ['./notification-page.style.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NotificationPageComponent { | ||
readonly notificationPermissionState$ = this.permissions.state('notifications'); | ||
|
||
readonly deniedPermissionNotification = | ||
'You have denied notification permission. Please, change it in browser settings.'; | ||
|
||
readonly gettingPermissionExample: TuiDocExample = { | ||
'index.ts': import('./examples/01-getting-permission/index.ts?raw'), | ||
'index.html': import('./examples/01-getting-permission/index.html?raw'), | ||
}; | ||
|
||
readonly createNotificationExample: TuiDocExample = { | ||
'index.ts': import('./examples/02-create-notification/index.ts?raw'), | ||
'index.html': import('./examples/02-create-notification/index.html?raw'), | ||
}; | ||
|
||
readonly closeNotificationExample: TuiDocExample = { | ||
'index.ts': import('./examples/03-close-notification/index.ts?raw'), | ||
'index.html': import('./examples/03-close-notification/index.html?raw'), | ||
}; | ||
|
||
readonly listenNotificationEventsExample: TuiDocExample = { | ||
'index.ts': import('./examples/04-listen-notification-events/index.ts?raw'), | ||
'index.html': import('./examples/04-listen-notification-events/index.html?raw'), | ||
}; | ||
|
||
constructor(private readonly permissions: PermissionsService) {} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/pages/notification/notification-page.module.ts
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,30 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {RouterModule} from '@angular/router'; | ||
import {TuiAddonDocModule} from '@taiga-ui/addon-doc'; | ||
import {TuiButtonModule, TuiNotificationModule} from '@taiga-ui/core'; | ||
import {TuiBadgeModule} from '@taiga-ui/kit'; | ||
import {NotificationPageExample1} from './examples/01-getting-permission'; | ||
import {NotificationPageExample2} from './examples/02-create-notification'; | ||
import {NotificationPageExample3} from './examples/03-close-notification'; | ||
import {NotificationPageExample4} from './examples/04-listen-notification-events'; | ||
import {NotificationPageComponent} from './notification-page.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
TuiAddonDocModule, | ||
TuiBadgeModule, | ||
TuiButtonModule, | ||
TuiNotificationModule, | ||
RouterModule.forChild([{path: '', component: NotificationPageComponent}]), | ||
], | ||
declarations: [ | ||
NotificationPageComponent, | ||
NotificationPageExample1, | ||
NotificationPageExample2, | ||
NotificationPageExample3, | ||
NotificationPageExample4, | ||
], | ||
}) | ||
export class NotificationPageModule {} |
21 changes: 21 additions & 0 deletions
21
apps/demo/src/app/pages/notification/notification-page.style.less
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,21 @@ | ||
:host { | ||
display: block; | ||
max-width: 900px; | ||
margin: 0 auto; | ||
font: var(--tui-font-text-m); | ||
} | ||
|
||
tui-notification { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.header { | ||
font: var(--tui-font-heading-4); | ||
display: flex; | ||
align-items: center; | ||
gap: 1rem; | ||
} | ||
|
||
.description { | ||
margin-bottom: 2rem; | ||
} |
Oops, something went wrong.