mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
* Fixes #2040 - Prevent the room list from staying empty after cancelling a search * Address PR comments, simplify implementation
This commit is contained in:
parent
5dcb24add7
commit
8d20cbfc68
@ -98,21 +98,20 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
.weakAssign(to: \.state.selectedRoomID, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
context.$viewState
|
||||
.map(\.bindings.searchQuery)
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] searchQuery in
|
||||
let isSearchFieldFocused = context.$viewState.map(\.bindings.isSearchFieldFocused)
|
||||
let searchQuery = context.$viewState.map(\.bindings.searchQuery)
|
||||
isSearchFieldFocused
|
||||
.combineLatest(searchQuery)
|
||||
.removeDuplicates { $0 == $1 }
|
||||
.map { _ in () }
|
||||
.sink { [weak self] in
|
||||
guard let self else { return }
|
||||
updateFilter(isSearchFieldFocused: state.bindings.isSearchFieldFocused, searchQuery: searchQuery)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
context.$viewState
|
||||
.map(\.bindings.isSearchFieldFocused)
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] isSearchFieldFocused in
|
||||
guard let self else { return }
|
||||
updateFilter(isSearchFieldFocused: isSearchFieldFocused, searchQuery: state.bindings.searchQuery)
|
||||
// Don't capture the values here as combine behaves incorrectly and `isSearchFieldFocused` is sometimes
|
||||
// turning to true after cancelling the search. Read them directly from the state in the updateFilter
|
||||
// method instead on the next run loop to make sure they're up to date.
|
||||
DispatchQueue.main.async {
|
||||
self.updateFilter()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@ -170,13 +169,13 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func updateFilter(isSearchFieldFocused: Bool, searchQuery: String) {
|
||||
if !isSearchFieldFocused {
|
||||
private func updateFilter() {
|
||||
if !state.bindings.isSearchFieldFocused {
|
||||
roomSummaryProvider?.setFilter(.all)
|
||||
} else if searchQuery.isEmpty {
|
||||
} else if state.bindings.searchQuery.isEmpty {
|
||||
roomSummaryProvider?.setFilter(.none)
|
||||
} else {
|
||||
roomSummaryProvider?.setFilter(.normalizedMatchRoomName(searchQuery))
|
||||
roomSummaryProvider?.setFilter(.normalizedMatchRoomName(state.bindings.searchQuery))
|
||||
}
|
||||
}
|
||||
|
||||
|
1
changelog.d/2040.bugfix
Normal file
1
changelog.d/2040.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Prevent the room list from staying empty after cancelling a search
|
Loading…
x
Reference in New Issue
Block a user