Fixes #1950 - Show a loading indicator while searching for people to … (#2158)

* Fixes #1950 - Show a loading indicator while searching for people to invite

* Address PR comments
This commit is contained in:
Stefan Ceriu 2023-11-23 19:56:49 +02:00 committed by GitHub
parent 33d36826a2
commit 07eccbee8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 9 deletions

View File

@ -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?

View File

@ -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)

View File

@ -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 {

1
changelog.d/1950.change Normal file
View File

@ -0,0 +1 @@
Show a loading indicator while searching for people to invite