Feature: store selected notification filter (#1627) (#1663)

* store selected notification filter (#1627)

* store one filter for all accounts
This commit is contained in:
Thai D. V 2023-11-16 15:53:16 +07:00 committed by GitHub
parent 58d6a3b472
commit 4b74532048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -39,6 +39,7 @@ public struct NotificationsListView: View {
}
}
}
.onAppear { viewModel.loadSelectedType() }
.toolbar {
ToolbarItem(placement: .principal) {
let title = lockedType?.menuTitle() ?? viewModel.selectedType?.menuTitle() ?? "notifications.navigation-title"

View File

@ -36,18 +36,35 @@ import SwiftUI
var currentAccount: CurrentAccount?
private let filterKey = "notification-filter"
var state: State = .loading
var selectedType: Models.Notification.NotificationType? {
didSet {
if oldValue != selectedType {
consolidatedNotifications = []
Task {
await fetchNotifications()
}
guard oldValue != selectedType,
let id = client?.id
else { return }
UserDefaults.standard.set(selectedType?.rawValue ?? "", forKey: filterKey)
consolidatedNotifications = []
Task {
await fetchNotifications()
}
}
}
func loadSelectedType() {
self.client = client
guard let value = UserDefaults.standard.string(forKey: filterKey)
else {
selectedType = nil
return
}
selectedType = .init(rawValue: value)
}
var scrollToTopVisible: Bool = false
private var queryTypes: [String]? {