#26: Add filtering of rooms by name.

* Add searchable to home screen.
* search ignoring case and accents
* Move home screen room search filtering to the ViewState
* Use lazy filtering for search.

Co-authored-by: Matthew Hodgson <matthew@matrix.org>
Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
Doug
2022-06-08 13:25:24 +01:00
committed by GitHub
parent 7879374927
commit be7c0e2ac9
3 changed files with 23 additions and 4 deletions

View File

@@ -35,23 +35,40 @@ struct HomeScreenViewState: BindableState {
var userAvatar: UIImage?
var rooms: [HomeScreenRoom] = []
var isLoadingRooms: Bool = false
var unencryptedDMs: [HomeScreenRoom] {
Array(rooms.filter { $0.isDirect && !$0.isEncrypted })
searchFilteredRooms.filter { $0.isDirect && !$0.isEncrypted }
}
var encryptedDMs: [HomeScreenRoom] {
Array(rooms.filter { $0.isDirect && $0.isEncrypted})
searchFilteredRooms.filter { $0.isDirect && $0.isEncrypted}
}
var unencryptedRooms: [HomeScreenRoom] {
Array(rooms.filter { !$0.isDirect && !$0.isEncrypted })
searchFilteredRooms.filter { !$0.isDirect && !$0.isEncrypted }
}
var encryptedRooms: [HomeScreenRoom] {
Array(rooms.filter { !$0.isDirect && $0.isEncrypted })
searchFilteredRooms.filter { !$0.isDirect && $0.isEncrypted }
}
private var searchFilteredRooms: LazyFilterSequence<LazySequence<[HomeScreenRoom]>.Elements> {
guard !bindings.searchQuery.isEmpty else {
// This extra filter is fine for now as there are always downstream filters
// but if that changes, this approach should be reconsidered.
return rooms.lazy.filter { _ in true }
}
return rooms.lazy.filter { $0.displayName?.localizedStandardContains(bindings.searchQuery) ?? false }
}
var bindings = HomeScreenViewStateBindings()
}
struct HomeScreenViewStateBindings {
var searchQuery: String = ""
}
struct HomeScreenRoom: Identifiable, Equatable {

View File

@@ -64,6 +64,7 @@ struct HomeScreen: View {
}
}
.listStyle(.plain)
.searchable(text: $context.searchQuery)
}
Spacer()

1
changelog.d/26.feature Normal file
View File

@@ -0,0 +1 @@
Add filtering for rooms by name.