From 53bfeab116206e212db30998ff6c0a291cb854cf Mon Sep 17 00:00:00 2001 From: Jan Szumotalski Date: Fri, 9 May 2025 12:47:01 +0200 Subject: [PATCH] Notifications fix (#5) --- .../admin-view/notifications/notifications.component.ts | 4 ++-- src/app/app-routing.module.ts | 3 ++- src/app/app-view/app-view.component.ts | 4 +--- src/app/services/auth.client.ts | 1 + src/app/services/local-storage.service.ts | 7 +++++++ src/environments/environment.development.ts | 3 --- src/environments/environment.ts | 1 - 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/admin-view/notifications/notifications.component.ts b/src/app/admin-view/notifications/notifications.component.ts index 7b98fda..9b5de2e 100644 --- a/src/app/admin-view/notifications/notifications.component.ts +++ b/src/app/admin-view/notifications/notifications.component.ts @@ -29,7 +29,7 @@ export class NotificationsComponent implements OnInit { uname: new FormControl(''), room: new FormControl(null), group: new FormControl(''), - type: new FormControl<"all" | "room" | "uname" | "group">('uname', {nonNullable: true}) + type: new FormControl<"room" | "uname" | "group">('uname', {nonNullable: true}) }), title: new FormControl('', {nonNullable: true}), body: new FormControl('', {nonNullable: true}) @@ -49,6 +49,6 @@ interface NotificationForm { uname: FormControl; room: FormControl; group: FormControl; - type: FormControl<"all" | "room" | "uname" | "group">; + type: FormControl<"room" | "uname" | "group">; }> } \ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a8748fb..c27adbb 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -18,6 +18,7 @@ import { GradesComponent } from './admin-view/grades/grades.component'; import { SummaryComponent } from './admin-view/grades/summary/summary.component'; import { SettingsComponent } from './admin-view/settings/settings.component'; import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component'; +import { NotificationsComponent } from './admin-view/notifications/notifications.component'; const routes: Routes = [ {path: "", redirectTo: "login", pathMatch: "full"}, @@ -32,7 +33,7 @@ const routes: Routes = [ {path: "news", title: "Edytowanie wiadomości", component: NewsEditComponent}, {path: "menu", title: "Edytowanie jadłospisu", component: MenuNewComponent}, {path: "accounts", title: "Użytkownicy", component: AccountMgmtComponent}, - // {path: "notifications", title: "Powiadomienia", component: NotificationsComponent}, + {path: "notifications", title: "Powiadomienia", component: NotificationsComponent}, {path: "groups", title: "Grupy", component: GroupsComponent}, {path: "keys", title: "Klucze", component: AdminKeyComponent}, {path: "grades", children: [ diff --git a/src/app/app-view/app-view.component.ts b/src/app/app-view/app-view.component.ts index cd674dc..a2bbe43 100644 --- a/src/app/app-view/app-view.component.ts +++ b/src/app/app-view/app-view.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { AuthClient } from '../services/auth.client'; import { SwPush } from '@angular/service-worker'; -import { environment } from 'src/environments/environment'; import { UpdatesService } from '../services/updates.service'; import { Link } from '../types/link'; import { LocalStorageService } from '../services/local-storage.service'; @@ -14,7 +13,6 @@ import { MatSnackBar } from '@angular/material/snack-bar'; styleUrls: ['./app-view.component.scss'] }) export class AppViewComponent implements OnInit { - readonly VAPID_PUK = environment.vapid.pubkey private readonly _LINKS: Link[] = [ { title: "Jadłospis", href: "menu", icon: "restaurant_menu", enabled: this.ls.capCheck(2) }, { title: "Wiadomości", href: "news", icon: "newspaper", enabled: this.ls.capCheck(1) }, @@ -32,7 +30,7 @@ export class AppViewComponent implements OnInit { subscribeToNotif() { if (this.swPush.isEnabled && this.ls.capCheck(4)) { this.swPush.requestSubscription({ - serverPublicKey: this.VAPID_PUK + serverPublicKey: this.ls.vapid }).then(sub => { this.us.postNotif(sub) }) diff --git a/src/app/services/auth.client.ts b/src/app/services/auth.client.ts index 61a778a..1b6be95 100644 --- a/src/app/services/auth.client.ts +++ b/src/app/services/auth.client.ts @@ -38,6 +38,7 @@ export class AuthClient { document.location.reload() } this.ls.room = data.room + this.ls.vapid = data.vapid if (data.menu.defaultItems) { this.ls.defaultItems = data.menu.defaultItems } diff --git a/src/app/services/local-storage.service.ts b/src/app/services/local-storage.service.ts index a669f11..59581d2 100644 --- a/src/app/services/local-storage.service.ts +++ b/src/app/services/local-storage.service.ts @@ -135,4 +135,11 @@ export class LocalStorageService { } public newsflag: number | false = false; + + public get vapid(): string { + return localStorage.getItem('vapid')! + } + public set vapid(value: string) { + localStorage.setItem("vapid", value) + } } diff --git a/src/environments/environment.development.ts b/src/environments/environment.development.ts index e5c3443..c95fff5 100644 --- a/src/environments/environment.development.ts +++ b/src/environments/environment.development.ts @@ -1,8 +1,5 @@ export const environment = { apiEndpoint: "http://localhost:12230", version: "testing", - vapid: { - pubkey: "" - }, production: false }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 7b5e3cf..71e63f7 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,6 +1,5 @@ export const environment = { apiEndpoint: `${window.location.origin}/api`, version: "v1.0.0", - vapid: { pubkey: "" }, production: true };