From 07eccbee8c1f022305607e39212da7041817f468 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 23 Nov 2023 19:56:49 +0200 Subject: [PATCH] =?UTF-8?q?Fixes=20#1950=20-=20Show=20a=20loading=20indica?= =?UTF-8?q?tor=20while=20searching=20for=20people=20to=20=E2=80=A6=20(#215?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes #1950 - Show a loading indicator while searching for people to invite * Address PR comments --- .../InviteUsersScreenModels.swift | 6 ++---- .../InviteUsersScreenViewModel.swift | 6 ++++++ .../View/InviteUsersScreen.swift | 17 ++++++++++++----- changelog.d/1950.change | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 changelog.d/1950.change diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift index 9ebaa1372..92ce28a8a 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenModels.swift @@ -41,12 +41,10 @@ struct InviteUsersScreenViewState: BindableState { var selectedUsers: [UserProfileProxy] = [] var membershipState: [String: MembershipState] = .init() - var isSearching: Bool { - !bindings.searchQuery.isEmpty - } + var isSearching = false var hasEmptySearchResults: Bool { - isSearching && usersSection.type == .searchResult && usersSection.users.isEmpty + !isSearching && usersSection.type == .searchResult && usersSection.users.isEmpty } var scrollToLastID: String? diff --git a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift index cf6e33144..375d4d260 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/InviteUsersScreenViewModel.swift @@ -134,6 +134,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr fetchSuggestions() return } + + state.isSearching = true fetchUsersTask = Task { let result = await userDiscoveryService.searchProfiles(with: searchQuery) guard !Task.isCancelled else { return } @@ -146,6 +148,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr state.usersSection = .init(type: .suggestions, users: []) return } + + state.isSearching = true fetchUsersTask = Task { let result = await userDiscoveryService.fetchSuggestions() guard !Task.isCancelled else { return } @@ -154,6 +158,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr } private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) { + state.isSearching = false + switch result { case .success(let users): state.usersSection = .init(type: sectionType, users: users) diff --git a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift index a7dc119f6..bb7011a56 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift @@ -40,15 +40,22 @@ struct InviteUsersScreen: View { private var mainContent: some View { Form { - if !context.viewState.selectedUsers.isEmpty { - // this is a fix for having the carousel not clipped, and inside the form, so when the search is dismissed, it wont break the design - Section { - EmptyView() - } header: { + // this is a fix for having the carousel not clipped, and inside the form, so when the search is dismissed, it wont break the design + Section { + EmptyView() + } header: { + VStack(spacing: 8) { selectedUsersSection .textCase(.none) + + if context.viewState.isSearching { + ProgressView() + .frame(maxWidth: .infinity, alignment: .center) + .listRowBackground(Color.clear) + } } } + if context.viewState.hasEmptySearchResults { noResultsContent } else { diff --git a/changelog.d/1950.change b/changelog.d/1950.change new file mode 100644 index 000000000..54c2a50ab --- /dev/null +++ b/changelog.d/1950.change @@ -0,0 +1 @@ +Show a loading indicator while searching for people to invite \ No newline at end of file