#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:
@@ -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 {
|
||||
|
||||
@@ -64,6 +64,7 @@ struct HomeScreen: View {
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.searchable(text: $context.searchQuery)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
1
changelog.d/26.feature
Normal file
1
changelog.d/26.feature
Normal file
@@ -0,0 +1 @@
|
||||
Add filtering for rooms by name.
|
||||
Reference in New Issue
Block a user