Fix project include list loading flicker

When opening the project include list the loading indicator would be removed before the list of projects would be
rendered. This turned out to be due to the interaction of several different observables firing at different times,
causing the loading indicator to be removed before the project list was filled. This PR fixes that, making sure the
loadign indicator will not get removed before the project list is actually filled

Co-authored-by: Oliver Günther <o.guenther@openproject.com>
pull/10615/head
Benjamin Bädorf 3 years ago
parent 2d4e55aa83
commit bdb36ccc39
No known key found for this signature in database
GPG Key ID: 069CA2D117AB5CCF
  1. 4
      frontend/src/app/shared/components/project-include/project-include.component.html
  2. 14
      frontend/src/app/shared/components/project-include/project-include.component.ts

@ -45,11 +45,7 @@
></span>
</spot-text-field>
<ng-container *ngIf="(projects$ | async)?.length > 0">
has projects
</ng-container>
<ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">
loading done
<ul
class="op-project-include--list"
op-project-list

@ -16,6 +16,7 @@ import {
finalize,
map,
mergeMap,
shareReplay,
take,
} from 'rxjs/operators';
@ -199,9 +200,16 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
),
),
map((projects) => recursiveSort(projects)),
shareReplay(),
);
public loading$ = new BehaviorSubject(false);
public fetchingProjects$ = new BehaviorSubject(false);
public loading$ = combineLatest([
this.fetchingProjects$,
this.projects$,
]).pipe(
map(([isFetching, projects]) => isFetching || projects.length === 0)
);
public get params():ApiV3ListParameters {
const filters:ApiV3ListFilter[] = [
@ -269,7 +277,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
}
public loadAllProjects():void {
this.loading$.next(true);
this.fetchingProjects$.next(true);
getPaginatedResults<IProject>(
(params) => {
@ -278,7 +286,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
},
)
.pipe(
finalize(() => this.loading$.next(false)),
finalize(() => this.fetchingProjects$.next(false)),
)
.subscribe((projects) => {
this.allProjects$.next(projects);

Loading…
Cancel
Save