Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[39828] Notification center empty state showing during loading (#10018)

Behrokh Satarnejad90deb1d6db53
diff --git a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.html b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.html
index 9e2144e8e18..c4067bde5d3 100644
--- a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.html
+++ b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.html
@@ -3,8 +3,8 @@
data-qa-selector="op-empty-state"
>
<div class="work-packages-tab-view--overflow op-empty-state--content">
- <ng-container *ngIf="(dataChanged$ | async ) as currentNotificationData; else loading">
- <ng-container *ngIf="currentNotificationData[0]; else noNotification">
+ <ng-container *ngIf="(loading$ | async) === false; else loading">
+ <ng-container *ngIf="(hasNotifications$ | async) as hasNotifications; else noNotification">
<img [src]="image.no_selection" class="op-empty-state--content-image"/>
<p class="op-empty-state--content-text">
<span>{{ text.no_selection }}</span>
@@ -13,7 +13,7 @@
<ng-template #noNotification>
<img [src]="image.no_notification" class="op-empty-state--content-image"/>
<p class="op-empty-state--content-text">
- <span [textContent]="noNotificationText(currentNotificationData[0], currentNotificationData[1])"></span>
+ <span [textContent]="noNotificationText(hasNotifications, (totalCount$ | async))"></span>
</p>
</ng-template>
diff --git a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts
index 2c81638715d..c4464f492db 100644
--- a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts
+++ b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts
@@ -59,18 +59,11 @@ export class EmptyStateComponent {
no_selection: this.I18n.t('js.notifications.center.empty_state.no_selection'),
};
- private hasNotifications$ = this.storeService.query.hasNotifications$;
+ hasNotifications$ = this.storeService.query.hasNotifications$;
- private totalCount$ = this.bellService.unread$;
+ totalCount$ = this.bellService.unread$;
- dataChanged$ = combineLatest([
- this.hasNotifications$,
- this.totalCount$,
- ])
- .pipe(
- distinctUntilChanged(),
- debounceTime(350),
- );
+ loading$ = this.storeService.query.selectLoading();
constructor(
readonly I18n:I18nService,
diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
index 600c1d04443..ee89167870a 100644
--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
@@ -1,9 +1,4 @@
<div class="op-ian-center">
- <div class="op-ian-center--loading-indicator" *ngIf="loading$ | async">
- <op-content-loader>
- <svg:rect x="0" y="0" width="100%" height="100%" rx="1" />
- </op-content-loader>
- </div>
<div class="op-ian-center--content">
<ng-container *ngIf="(hasNotifications$ | async); else noResults">
<cdk-virtual-scroll-viewport
diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
index 0bdde2163bd..34f301257f5 100644
--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts
@@ -11,6 +11,7 @@ import {
shareReplay,
switchMap,
take,
+ tap,
} from 'rxjs/operators';
import {
from,
@@ -67,11 +68,14 @@ export class IanCenterService extends UntilDestroyedMixin {
private onReload = this.reload.pipe(
debounceTime(0),
- switchMap((setToLoading) => this.resourceService
+ tap((setToLoading) => {
+ if (setToLoading) {
+ this.store.setLoading(true);
+ }
+ }),
+ switchMap(() => this.resourceService
.fetchNotifications(this.query.params)
.pipe(
- // We don't want to set loading if the request is sent in the background
- setToLoading ? setLoading(this.store) : map((res) => res),
switchMap(
(results) => from(this.sideLoadInvolvedWorkPackages(results._embedded.elements))
.pipe(
@@ -79,6 +83,14 @@ export class IanCenterService extends UntilDestroyedMixin {
),
),
)),
+
+ // We need to be slower than the onReload subscribers set below.
+ // Because they're subscribers they're called next in the callback queue.
+ // We need our loading state to be set to false only after all data is in the store,
+ // but we cannot guarantee that here, since the data is set _after_ this piece of code
+ // gets run. The solution is to queue this piece of code back, allowing the store contents
+ // update before the loading state gets reset.
+ tap(() => setTimeout(() => this.store.setLoading(false))),
);
public selectedNotificationIndex = 0;