From db75044386a5df163cba1412d0e3cd2e7c761891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 2 Mar 2020 11:42:51 +0100 Subject: [PATCH] MOBILE-3281 users: Keep selected item if present in list --- .../components/participants/participants.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/user/components/participants/participants.ts b/src/core/user/components/participants/participants.ts index bcb4edce8..23e8fb2e5 100644 --- a/src/core/user/components/participants/participants.ts +++ b/src/core/user/components/participants/participants.ts @@ -161,16 +161,10 @@ export class CoreUserParticipantsComponent implements OnInit { this.displaySearchResults = false; this.participants = []; this.searchPage = 0; - this.splitviewCtrl.emptyDetails(); // Remove search results and display all participants. this.participantsLoaded = false; - this.fetchData(true).then(() => { - if (this.splitviewCtrl.isOn() && this.participants.length > 0) { - // Take first and load it. - this.gotoParticipant(this.participants[0].id); - } - }); + this.fetchData(true); } /** @@ -201,9 +195,19 @@ export class CoreUserParticipantsComponent implements OnInit { this.canLoadMore = result.canLoadMore; this.searchPage++; - if (!loadMore && this.splitviewCtrl.isOn() && this.participants.length > 0) { - // Take first and load it. - this.gotoParticipant(this.participants[0].id); + if (!loadMore && this.splitviewCtrl.isOn()) { + // Load the first entry. + if (this.participants.length > 0) { + const found = this.participantId && this.participants.some((user) => user.id == this.participantId); + + // The current selected user is not found in the current list, open first item. + if (!found) { + this.gotoParticipant(this.participants[0].id); + } + } else { + this.participantId = null; + this.splitviewCtrl.emptyDetails(); + } } }).catch((error) => {