From 7c652f6b87d9d4d3e34f90f6508d15a188fb5cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Tue, 14 Jun 2022 14:05:43 +0300 Subject: [PATCH] RED-4162: Refresh notifications after preferences update --- .../services/notification-preferences.service.ts | 15 ++++++++++----- .../src/app/services/notifications.service.ts | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts b/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts index 0d875dfed..c2248de92 100644 --- a/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts +++ b/apps/red-ui/src/app/modules/account/services/notification-preferences.service.ts @@ -1,13 +1,18 @@ import { Injectable, Injector } from '@angular/core'; import { GenericService } from '@iqser/common-ui'; -import { Observable, of } from 'rxjs'; +import { Observable, of, switchMap } from 'rxjs'; import { UserService } from '@services/user.service'; -import { EmailNotificationScheduleTypes, INotificationPreferences } from '@red/domain'; +import { EmailNotificationScheduleTypes, INotificationPreferences, Notification } from '@red/domain'; import { catchError } from 'rxjs/operators'; +import { NotificationsService } from '@services/notifications.service'; @Injectable() export class NotificationPreferencesService extends GenericService { - constructor(protected readonly _injector: Injector, private readonly _userService: UserService) { + constructor( + protected readonly _injector: Injector, + private readonly _userService: UserService, + private readonly _notificationsService: NotificationsService, + ) { super(_injector, 'notification-preferences'); } @@ -25,7 +30,7 @@ export class NotificationPreferencesService extends GenericService().pipe(catchError(() => of(this._defaultPreferences))); } - update(notificationPreferences: INotificationPreferences): Observable { - return super._post(notificationPreferences); + update(notificationPreferences: INotificationPreferences): Observable { + return super._post(notificationPreferences).pipe(switchMap(() => this._notificationsService.loadAll())); } } diff --git a/apps/red-ui/src/app/services/notifications.service.ts b/apps/red-ui/src/app/services/notifications.service.ts index 0066d9c0c..08b1524f7 100644 --- a/apps/red-ui/src/app/services/notifications.service.ts +++ b/apps/red-ui/src/app/services/notifications.service.ts @@ -47,10 +47,10 @@ export class NotificationsService extends EntitiesService this.#loadAll())); + return this._post(body, `${this._defaultModelPath}/toggle-read`, [queryParam]).pipe(switchMap(() => this.loadAll())); } - #loadAll(includeSeen = INCLUDE_SEEN): Observable { + loadAll(includeSeen = INCLUDE_SEEN): Observable { const queryParam: QueryParam = { key: 'includeSeen', value: includeSeen }; return this.getAll<{ notifications: Notification[] }>(this._defaultModelPath, [queryParam]).pipe( @@ -61,7 +61,7 @@ export class NotificationsService extends EntitiesService { - return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.#loadAll(), EMPTY))); + return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.loadAll(), EMPTY))); } private _new(notification: INotification) {