Search Communities: Fix a bug with parsing results

This commit is contained in:
Konstantinos Triantafyllou 2021-11-05 14:11:38 +02:00
parent 69b4d10384
commit 4fd401297c
1 changed files with 11 additions and 9 deletions

View File

@ -117,6 +117,14 @@ export class SearchCommunitiesComponent {
});
}
private parseResults(data: any) {
for (let i = 0; i < data.length; i++) {
this.totalResults[i] = data[i];
this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]);
this.totalResults[i].isSubscribed = Session.isSubscribedTo('community', this.totalResults[i].communityId, this.user);
}
}
/**
* Initialize communities from Communities APIs
*
@ -124,19 +132,13 @@ export class SearchCommunitiesComponent {
*/
private initCommunities(params) {
if(this.totalResults) {
this.parseResults(this.totalResults);
this._getResults(params);
} else {
this.totalResults = [];
this.subscriptions.push(this._communitiesService.getCommunitiesState().subscribe(
data => {
if (!data) {
return;
}
for (let i = 0; i < data.length; i++) {
this.totalResults[i] = data[i];
this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]);
this.totalResults[i].isSubscribed = Session.isSubscribedTo('community', this.totalResults[i].communityId, this.user);
}
this.totalResults = [];
this.parseResults(data);
this._getResults(params);
},
err => {