diff options
Diffstat (limited to 'Hutch/Views/Inbox')
| -rw-r--r-- | Hutch/Views/Inbox/InboxView.swift | 9 | ||||
| -rw-r--r-- | Hutch/Views/Inbox/InboxViewModel.swift | 11 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Hutch/Views/Inbox/InboxView.swift b/Hutch/Views/Inbox/InboxView.swift index 74f78d5..5724964 100644 --- a/Hutch/Views/Inbox/InboxView.swift +++ b/Hutch/Views/Inbox/InboxView.swift @@ -30,7 +30,7 @@ struct InboxView: View { @Bindable var vm = viewModel List { - ForEach(viewModel.threads) { thread in + ForEach(viewModel.filteredThreads) { thread in Button { selectThread(thread) } label: { @@ -45,6 +45,11 @@ struct InboxView: View { } } } + .searchable( + text: $vm.searchText, + placement: .navigationBarDrawer(displayMode: .always), + prompt: "Search inbox" + ) .listStyle(.plain) .overlay { if viewModel.isLoading, viewModel.threads.isEmpty { @@ -55,6 +60,8 @@ struct InboxView: View { message: error, retryAction: { await viewModel.loadThreads() } ) + } else if !viewModel.threads.isEmpty, viewModel.filteredThreads.isEmpty { + ContentUnavailableView.search(text: viewModel.searchText) } else if viewModel.threads.isEmpty, viewModel.error == nil { ContentUnavailableView( "Inbox Zero", diff --git a/Hutch/Views/Inbox/InboxViewModel.swift b/Hutch/Views/Inbox/InboxViewModel.swift index 00d47b5..42ce223 100644 --- a/Hutch/Views/Inbox/InboxViewModel.swift +++ b/Hutch/Views/Inbox/InboxViewModel.swift @@ -62,6 +62,7 @@ final class InboxViewModel { private(set) var threads: [InboxThreadSummary] = [] private(set) var isLoading = false var error: String? + var searchText = "" private let client: SRHTClient private let listThreadFetchLimit = 10 @@ -164,6 +165,16 @@ final class InboxViewModel { threads.first(where: { $0.id == id }) } + var filteredThreads: [InboxThreadSummary] { + let q = searchText.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() + guard !q.isEmpty else { return threads } + return threads.filter { + $0.displaySubject.lowercased().contains(q) || + $0.listName.lowercased().contains(q) || + $0.latestSender.canonicalName.lowercased().contains(q) + } + } + private func fetchSubscriptions() async throws -> [InboxActivitySubscription] { var subscriptions: [InboxActivitySubscription] = [] var cursor: String? |
