Skip to content

Commit 438fbe2

Browse files
Merge remote-tracking branch 'origin/129-hot-bugfixes' into 129-hot-bugfixes
2 parents 9e11631 + cc4d753 commit 438fbe2

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

src/app/core/header/navigation/notification/notification.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ <h2 mat-dialog-title><span class="underline">Notifications</span></h2>
4646
<th mat-header-cell *matHeaderCellDef>Link</th>
4747
<td mat-cell *matCellDef="let element">
4848
<div class="dialog-container__link">
49-
<a mat-icon-button *ngIf="element.link" [routerLink]="element.link"
49+
<a mat-icon-button *ngIf="element.link"
50+
[routerLink]="element.link.split('?')[0]"
51+
[queryParams]="{highlight: element.link.split('?')[1].split('=')[1]}"
5052
tabindex="-1" (click)="markAsRead(element)" matDialogClose>
5153
<mat-icon>arrow_forward</mat-icon>
5254
</a>

src/app/core/services/user-notification.service.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,46 @@ import {tap} from "rxjs/operators";
88
})
99
export class UserNotificationService {
1010
private notificationData = new Subject<IncomingNotification>();
11-
private notification$ = this.notificationData.asObservable();
11+
private notifiedNotificationData = new Subject<IncomingNotification>();
12+
private notification$ = this.notifiedNotificationData.asObservable();
1213
private readonly hasVibrationSupport;
14+
private readonly hasNotificationSupport;
15+
private hasGrantedNotificationSupport;
1316

1417
constructor() {
1518
this.hasVibrationSupport = !!window.navigator.vibrate;
16-
}
17-
18-
getNotification(): Observable<IncomingNotification> {
19-
return this.notification$.pipe(
19+
this.hasNotificationSupport = !!window.Notification;
20+
if(this.hasNotificationSupport){
21+
this.hasGrantedNotificationSupport = Notification.permission === "granted";
22+
if(!this.hasGrantedNotificationSupport){
23+
Notification.requestPermission().then(()=>{
24+
this.hasGrantedNotificationSupport = Notification.permission === "granted";
25+
});
26+
}
27+
}
28+
this.notificationData.pipe(
2029
tap(val => {
21-
if (this.hasVibrationSupport) {
22-
window.navigator.vibrate(400);
30+
if(this.hasNotificationSupport && this.hasGrantedNotificationSupport){
31+
console.log(`Notifying`, val);
32+
new Notification('RiverSurf', {
33+
body: val.content,
34+
tag: val.surfEventName,
35+
icon: '/assets/icons/icon-512x512.png',
36+
vibrate: 400
37+
});
38+
} else {
39+
if (this.hasVibrationSupport) {
40+
window.navigator.vibrate(400);
41+
}
2342
}
2443
})
25-
);
44+
).subscribe(val => {
45+
this.notifiedNotificationData.next(val);
46+
});
47+
}
48+
49+
getNotification(): Observable<IncomingNotification> {
50+
return this.notification$;
2651
}
2752

2853
showNotification(notification: IncomingNotification) {

src/app/core/services/web-socket.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class WebSocketService {
116116
};
117117

118118
if (message.payload.timestamp && message.payload.content) {
119-
notificationMessage.payload.surfEventName = message.payload.surfeventName;
119+
notificationMessage.payload.surfEventName = message.payload.surfEventName;
120120
notificationMessage.payload.timestamp = message.payload.timestamp;
121121
notificationMessage.payload.content = message.payload.content;
122122
notificationMessage.payload.link = message.payload.link;

src/app/surf-event/result-view/result-view.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ export class ResultViewComponent implements OnInit, AfterViewInit, OnDestroy {
6464

6565
qrCodeLink?: string;
6666
selectedDivision?: Division;
67-
isOffline: boolean = false;
67+
isOffline!: boolean;
68+
6869
private windowResizeSubject$ = new Subject<number | null>();
6970
private selectedSurfEvent: string = '';
71+
7072
private destroy$ = new Subject();
7173

7274
constructor(private cd: ChangeDetectorRef,
@@ -131,12 +133,14 @@ export class ResultViewComponent implements OnInit, AfterViewInit, OnDestroy {
131133
this.qrCodeLink = window.location.toString();
132134

133135
this.surfEventService.getCompetitionUpdates().subscribe(
134-
() => {
136+
(competitions) => {
135137
if (this.competition) {
136-
this.lines = [];
137-
this.points = [];
138-
this.cd.detectChanges();
139-
this.getPointsAndLines();
138+
if (competitions.findIndex(competition => competition.id === this.competition.id) !== -1) {
139+
this.lines = [];
140+
this.points = [];
141+
this.cd.detectChanges();
142+
this.getPointsAndLines();
143+
}
140144
}
141145
}
142146
)
@@ -369,10 +373,7 @@ export class ResultViewComponent implements OnInit, AfterViewInit, OnDestroy {
369373
this.highlightActive = false;
370374
this.router.navigate(['../', this.selectedDivision], {
371375
relativeTo: this.route
372-
}).then(
373-
() => {
374-
}
375-
);
376+
}).then();
376377

377378

378379
}

0 commit comments

Comments
 (0)