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
4 changed files with 21 additions and 9 deletions
@@ -41,12 +41,10 @@ struct InviteUsersScreenViewState: BindableState {
var selectedUsers: [UserProfileProxy] = [] var selectedUsers: [UserProfileProxy] = []
var membershipState: [String: MembershipState] = .init() var membershipState: [String: MembershipState] = .init()
var isSearching: Bool { var isSearching = false
!bindings.searchQuery.isEmpty
}
var hasEmptySearchResults: Bool { var hasEmptySearchResults: Bool {
isSearching && usersSection.type == .searchResult && usersSection.users.isEmpty !isSearching && usersSection.type == .searchResult && usersSection.users.isEmpty
} }
var scrollToLastID: String? var scrollToLastID: String?
@@ -134,6 +134,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
fetchSuggestions() fetchSuggestions()
return return
} }
state.isSearching = true
fetchUsersTask = Task { fetchUsersTask = Task {
let result = await userDiscoveryService.searchProfiles(with: searchQuery) let result = await userDiscoveryService.searchProfiles(with: searchQuery)
guard !Task.isCancelled else { return } guard !Task.isCancelled else { return }
@@ -146,6 +148,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
state.usersSection = .init(type: .suggestions, users: []) state.usersSection = .init(type: .suggestions, users: [])
return return
} }
state.isSearching = true
fetchUsersTask = Task { fetchUsersTask = Task {
let result = await userDiscoveryService.fetchSuggestions() let result = await userDiscoveryService.fetchSuggestions()
guard !Task.isCancelled else { return } guard !Task.isCancelled else { return }
@@ -154,6 +158,8 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
} }
private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) { private func handleResult(for sectionType: UserDiscoverySectionType, result: Result<[UserProfileProxy], UserDiscoveryErrorType>) {
state.isSearching = false
switch result { switch result {
case .success(let users): case .success(let users):
state.usersSection = .init(type: sectionType, users: users) state.usersSection = .init(type: sectionType, users: users)
@@ -40,15 +40,22 @@ struct InviteUsersScreen: View {
private var mainContent: some View { private var mainContent: some View {
Form { 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
// 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 {
Section { EmptyView()
EmptyView() } header: {
} header: { VStack(spacing: 8) {
selectedUsersSection selectedUsersSection
.textCase(.none) .textCase(.none)
if context.viewState.isSearching {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
.listRowBackground(Color.clear)
}
} }
} }
if context.viewState.hasEmptySearchResults { if context.viewState.hasEmptySearchResults {
noResultsContent noResultsContent
} else { } else {
+1
View File
@@ -0,0 +1 @@
Show a loading indicator while searching for people to invite