Skip to content

Commit

Permalink
In app notifications (#1509)
Browse files Browse the repository at this point in the history

* handle in app notification test
  • Loading branch information
yzlucas authored Dec 15, 2023
1 parent 9d13aba commit 5a9813c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, Inject } from "@angular/core";
import { MatSnackBarRef, MAT_SNACK_BAR_DATA } from "@angular/material/snack-bar";
import { Router } from "@angular/router";
import { ResourcesRoutes } from "@app/utils";

export type NotificationConfig = {
title: string
Expand All @@ -11,7 +13,7 @@ export type NotificationConfig = {
template: `
<div matSnackBarActions>
<span matSnackBarAction matSnackBarLabel class="snackbar"
(click)="snackBarRef.dismissWithAction()"
(click)="selectNotification()"
>
<span class="icon"></span>
<span class="content">
Expand All @@ -30,14 +32,34 @@ export type NotificationConfig = {
export class NotificationSnackbarComponent {
constructor(
public snackBarRef: MatSnackBarRef<NotificationSnackbarComponent>,
@Inject(MAT_SNACK_BAR_DATA) public data: NotificationConfig
protected router: Router,
@Inject(MAT_SNACK_BAR_DATA) public data: any
) { }

get title() {
return this.data.title
return this.data.notification.title
}

get body() {
return this.data.body
return this.data.notification.body
}

selectNotification() {
const notification = this.data.notification
let c = JSON.parse(notification.data['coords']),
r = JSON.parse(notification.data['radius'])
this.router.navigate([ResourcesRoutes.ACTIVEWILDFIREMAP], {
queryParams: {
latitude: c[0],
longitude: c[1],
radius: r,
featureId: notification.data['messageID'],
featureType: notification.data['topicKey'],
identify:true,
notification:true,
time: Date.now()
}
});
this.snackBarRef.dismiss();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class CapacitorService {

this.notificationSnackbarPromise = this.notificationSnackbarPromise.then( () => {
return new Promise( ( res, rej ) => {
let sb = this.showNotificationSnackbar( notification.title, notification.body )
let sb = this.showNotificationSnackbar(notification)

sb.onAction().subscribe( () => {
this.emitLocationNotification(notification.body )
Expand Down Expand Up @@ -276,7 +276,7 @@ export class CapacitorService {

this.notificationSnackbarPromise = this.notificationSnackbarPromise.then( () => {
return new Promise( ( res, rej ) => {
let sb = this.showNotificationSnackbar( notification.title, notification.body )
let sb = this.showNotificationSnackbar(notification)

sb.onAction().subscribe( () => {
let c = JSON.parse(notification.data['coords']),
Expand Down Expand Up @@ -326,9 +326,9 @@ export class CapacitorService {
}, this.locationNotificationsDelay );
}

showNotificationSnackbar( title: string, body: string ) {
let cfg: MatSnackBarConfig<NotificationConfig> = {
data: { title, body },
showNotificationSnackbar( notification: any) {
let cfg: MatSnackBarConfig<any> = {
data: {notification},
// need to change back to 10 sec. Using 60 sec for testing purpose in case QA missed it.
duration: 60 * 1000,
verticalPosition: 'top'
Expand Down

0 comments on commit 5a9813c

Please sign in to comment.