diff options
| author | Christian Cleberg <[email protected]> | 2026-04-12 00:34:54 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-12 00:34:54 -0500 |
| commit | 5f6d545eb3455a9e4da5a3cb4460811e3a48d939 (patch) | |
| tree | 7b7591146da4e02bd617ddb9f26e47b1c4474ef6 /Hutch/Views/Inbox/InboxViewModel.swift | |
| parent | cb1ea5ea4f163d87053285d3fb7999b12a3558b9 (diff) | |
| download | hutch-5f6d545eb3455a9e4da5a3cb4460811e3a48d939.tar.gz hutch-5f6d545eb3455a9e4da5a3cb4460811e3a48d939.tar.bz2 hutch-5f6d545eb3455a9e4da5a3cb4460811e3a48d939.zip | |
improve home attention flows and cross-linkingv2.14.0
Diffstat (limited to 'Hutch/Views/Inbox/InboxViewModel.swift')
| -rw-r--r-- | Hutch/Views/Inbox/InboxViewModel.swift | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Hutch/Views/Inbox/InboxViewModel.swift b/Hutch/Views/Inbox/InboxViewModel.swift index edb7593..a01f836 100644 --- a/Hutch/Views/Inbox/InboxViewModel.swift +++ b/Hutch/Views/Inbox/InboxViewModel.swift @@ -56,12 +56,19 @@ private struct InboxEmailPreview: Decodable, Sendable { let patch: InboxPatchPreview? } +enum InboxThreadFilter: String, CaseIterable, Sendable { + case all = "All" + case patches = "Patches" + case discussions = "Talk" +} + @Observable @MainActor final class InboxViewModel { private(set) var threads: [InboxThreadSummary] = [] private(set) var isLoading = false var error: String? + var filter: InboxThreadFilter = .all var searchText = "" private let client: SRHTClient @@ -181,9 +188,10 @@ final class InboxViewModel { } var filteredThreads: [InboxThreadSummary] { + let filteredByKind = Self.filterThreads(threads, filter: filter) let q = searchText.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() - guard !q.isEmpty else { return threads } - return threads.filter { + guard !q.isEmpty else { return filteredByKind } + return filteredByKind.filter { $0.displaySubject.lowercased().contains(q) || $0.listName.lowercased().contains(q) || $0.latestSender.canonicalName.lowercased().contains(q) @@ -389,4 +397,17 @@ final class InboxViewModel { } return nil } + + nonisolated static func filterThreads(_ threads: [InboxThreadSummary], filter: InboxThreadFilter) -> [InboxThreadSummary] { + threads.filter { thread in + switch filter { + case .all: + return true + case .patches: + return thread.containsPatch + case .discussions: + return !thread.containsPatch + } + } + } } |
