mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 20:09:04 +00:00
* Fixes #1950 - Show a loading indicator while searching for people to invite * Address PR comments
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Show a loading indicator while searching for people to invite
|
||||||
Reference in New Issue
Block a user