From 74cd70d8609c2d3d703ca921fa7af29e9a2dd1e5 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Sun, 30 Apr 2023 13:19:00 +0100 Subject: [PATCH] Fixed communities collection and sub-community sorting not working after page refresh --- ...nity-page-sub-collection-list.component.ts | 17 +++++++++----- ...unity-page-sub-community-list.component.ts | 23 ++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts b/src/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts index 181ee7cd6f..3a77149e5b 100644 --- a/src/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts +++ b/src/app/community-page/sub-collection-list/community-page-sub-collection-list.component.ts @@ -1,4 +1,5 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs'; @@ -49,19 +50,23 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro */ subCollectionsRDObs: BehaviorSubject>> = new BehaviorSubject>>({} as any); - constructor(private cds: CollectionDataService, - private paginationService: PaginationService, - - ) {} + constructor( + protected cds: CollectionDataService, + protected paginationService: PaginationService, + protected route: ActivatedRoute, + ) { + } ngOnInit(): void { this.config = new PaginationComponentOptions(); this.config.id = this.pageId; if (hasValue(this.pageSize)) { this.config.pageSize = this.pageSize; + } else { + this.config.pageSize = this.route.snapshot.queryParams[this.pageId + '.rpp'] ?? this.config.pageSize; } - this.config.currentPage = 1; - this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); + this.config.currentPage = this.route.snapshot.queryParams[this.pageId + '.page'] ?? 1; + this.sortConfig = new SortOptions('dc.title', SortDirection[this.route.snapshot.queryParams[this.pageId + '.sd']] ?? SortDirection.ASC); this.initPage(); } diff --git a/src/app/community-page/sub-community-list/community-page-sub-community-list.component.ts b/src/app/community-page/sub-community-list/community-page-sub-community-list.component.ts index e9da10bfa1..5a0409a051 100644 --- a/src/app/community-page/sub-community-list/community-page-sub-community-list.component.ts +++ b/src/app/community-page/sub-community-list/community-page-sub-community-list.component.ts @@ -1,4 +1,5 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { BehaviorSubject, combineLatest as observableCombineLatest } from 'rxjs'; @@ -9,7 +10,6 @@ import { PaginatedList } from '../../core/data/paginated-list.model'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { CommunityDataService } from '../../core/data/community-data.service'; -import { takeUntilCompletedRemoteData } from '../../core/shared/operators'; import { switchMap } from 'rxjs/operators'; import { PaginationService } from '../../core/pagination/pagination.service'; import { hasValue } from '../../shared/empty.util'; @@ -52,8 +52,10 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy */ subCommunitiesRDObs: BehaviorSubject>> = new BehaviorSubject>>({} as any); - constructor(private cds: CommunityDataService, - private paginationService: PaginationService + constructor( + protected cds: CommunityDataService, + protected paginationService: PaginationService, + protected route: ActivatedRoute, ) { } @@ -62,9 +64,11 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy this.config.id = this.pageId; if (hasValue(this.pageSize)) { this.config.pageSize = this.pageSize; + } else { + this.config.pageSize = this.route.snapshot.queryParams[this.pageId + '.rpp'] ?? this.config.pageSize; } - this.config.currentPage = 1; - this.sortConfig = new SortOptions('dc.title', SortDirection.ASC); + this.config.currentPage = this.route.snapshot.queryParams[this.pageId + '.page'] ?? 1; + this.sortConfig = new SortOptions('dc.title', SortDirection[this.route.snapshot.queryParams[this.pageId + '.sd']] ?? SortDirection.ASC); this.initPage(); } @@ -86,15 +90,6 @@ export class CommunityPageSubCommunityListComponent implements OnInit, OnDestroy ).subscribe((results) => { this.subCommunitiesRDObs.next(results); }); - - - this.cds.findByParent(this.community.id, { - currentPage: this.config.currentPage, - elementsPerPage: this.config.pageSize, - sort: { field: this.sortConfig.field, direction: this.sortConfig.direction } - }).pipe(takeUntilCompletedRemoteData()).subscribe((results) => { - this.subCommunitiesRDObs.next(results); - }); } ngOnDestroy(): void {