Skip to content

Commit

Permalink
Fixes #1950 - Show a loading indicator while searching for people to … (
Browse files Browse the repository at this point in the history
#2158)

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

* Address PR comments
  • Loading branch information
stefanceriu authored Nov 23, 2023
1 parent 33d3682 commit 07eccbe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1950.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show a loading indicator while searching for people to invite

0 comments on commit 07eccbe

Please sign in to comment.