mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:31:27 +00:00
Show recent searches on the search screen
The search screen's empty state now lists the queries the user searched for and the rooms they opened from the results, newest first, capped at 25 and stored in AppSettings. Tapping a query fills the search field, tapping a room opens it, and both are reachable with a hardware keyboard. Rooms are resolved from their identifiers as the room list loads, and those the user has left or is only invited to are dropped. The history is cleared on logout.
This commit is contained in:
@@ -31,6 +31,7 @@ enum SearchScreenMode: CaseIterable, Identifiable {
|
||||
struct SearchScreenViewState: BindableState {
|
||||
var rooms = [SearchScreenRoom]()
|
||||
var messages = [SearchScreenMessage]()
|
||||
var breadcrumbs = [SearchScreenBreadcrumb]()
|
||||
var isLoadingRooms = false
|
||||
var isLoadingMessages = false
|
||||
var bindings: SearchScreenViewStateBindings
|
||||
@@ -59,6 +60,32 @@ struct SearchScreenRoom: Identifiable, Equatable {
|
||||
let title: String
|
||||
let description: String
|
||||
let avatar: RoomAvatar
|
||||
|
||||
init(_ summary: RoomSummary) {
|
||||
let identifier = if summary.isDirect {
|
||||
summary.heroes.first?.id ?? summary.canonicalAlias
|
||||
} else {
|
||||
summary.canonicalAlias
|
||||
}
|
||||
|
||||
id = summary.id
|
||||
title = summary.name
|
||||
description = identifier ?? ""
|
||||
avatar = summary.avatar
|
||||
}
|
||||
}
|
||||
|
||||
/// An entry in the search history shown before the user has typed a query.
|
||||
enum SearchScreenBreadcrumb: Identifiable, Equatable {
|
||||
case query(String)
|
||||
case room(SearchScreenRoom)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .query(let query): "query-\(query)"
|
||||
case .room(let room): "room-\(room.id)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SearchScreenMessage: Identifiable, Equatable {
|
||||
|
||||
Reference in New Issue
Block a user