feat: Added notification dialog on frontend
This commit is contained in:
@@ -6,6 +6,8 @@ import { Link } from '../types/link';
|
||||
import { LocalStorageService } from '../services/local-storage.service';
|
||||
import { interval } from 'rxjs';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { NotifDialogComponent } from './notif-dialog/notif-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-app-view',
|
||||
@@ -25,7 +27,14 @@ export class AppViewComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
constructor (private ac: AuthClient, readonly swPush: SwPush, private us: UpdatesService, private ls: LocalStorageService, private sb: MatSnackBar) {}
|
||||
constructor (
|
||||
private ac: AuthClient,
|
||||
readonly swPush: SwPush,
|
||||
private us: UpdatesService,
|
||||
private ls: LocalStorageService,
|
||||
private sb: MatSnackBar,
|
||||
private dialog: MatDialog
|
||||
) {}
|
||||
|
||||
subscribeToNotif() {
|
||||
if (this.swPush.isEnabled && this.ls.capCheck(4)) {
|
||||
@@ -45,6 +54,13 @@ export class AppViewComponent implements OnInit {
|
||||
}
|
||||
|
||||
newsCheck() {
|
||||
if (this.ls.capCheck(4)) {
|
||||
this.us.getNotifCheck().subscribe((s) => {
|
||||
s.forEach(v => {
|
||||
this.dialog.open(NotifDialogComponent, {data: v})
|
||||
})
|
||||
})
|
||||
}
|
||||
if (this.ls.newsflag) return;
|
||||
this.us.newsCheck().subscribe((s) => {
|
||||
if (s.hash != this.ls.newsCheck.hash) {
|
||||
|
||||
10
src/app/app-view/notif-dialog/notif-dialog.component.html
Normal file
10
src/app/app-view/notif-dialog/notif-dialog.component.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<h1 mat-dialog-title>{{data.message.title}}</h1>
|
||||
<mat-dialog-content>
|
||||
<p>
|
||||
{{data.message.body}}
|
||||
</p>
|
||||
<div>{{data.sentDate.format("[Wysłano] dddd DD MMMM YYYYr. o HH:mm")}}</div>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-raised-button color="primary" (click)="ack()">Odczytano</button>
|
||||
</mat-dialog-actions>
|
||||
23
src/app/app-view/notif-dialog/notif-dialog.component.spec.ts
Normal file
23
src/app/app-view/notif-dialog/notif-dialog.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotifDialogComponent } from './notif-dialog.component';
|
||||
|
||||
describe('NotifDialogComponent', () => {
|
||||
let component: NotifDialogComponent;
|
||||
let fixture: ComponentFixture<NotifDialogComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [NotifDialogComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(NotifDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
27
src/app/app-view/notif-dialog/notif-dialog.component.ts
Normal file
27
src/app/app-view/notif-dialog/notif-dialog.component.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import * as moment from 'moment';
|
||||
import { UpdatesService } from 'src/app/services/updates.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-notif-dialog',
|
||||
templateUrl: './notif-dialog.component.html',
|
||||
styleUrl: './notif-dialog.component.scss'
|
||||
})
|
||||
export class NotifDialogComponent {
|
||||
|
||||
constructor (
|
||||
@Inject(MAT_DIALOG_DATA) public data: {_id: string, message: {title: string, body: string}, sentDate: moment.Moment},
|
||||
public dialogRef: MatDialogRef<NotifDialogComponent>,
|
||||
private uc: UpdatesService
|
||||
) {
|
||||
data.sentDate = moment(data.sentDate)
|
||||
}
|
||||
|
||||
ack () {
|
||||
this.uc.postInfoAck(this.data._id).subscribe((v) => {
|
||||
this.dialogRef.close()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user