Fix notifications reload

This commit is contained in:
Thomas Ricouard 2023-12-28 13:48:50 +01:00
parent 00e35be2d5
commit b83f7e9a55
2 changed files with 12 additions and 8 deletions

View file

@ -39,7 +39,6 @@ public struct NotificationsListView: View {
} }
} }
} }
.onAppear { viewModel.loadSelectedType() }
.toolbar { .toolbar {
ToolbarItem(placement: .principal) { ToolbarItem(placement: .principal) {
let title = lockedType?.menuTitle() ?? viewModel.selectedType?.menuTitle() ?? "notifications.navigation-title" let title = lockedType?.menuTitle() ?? viewModel.selectedType?.menuTitle() ?? "notifications.navigation-title"
@ -64,6 +63,9 @@ public struct NotificationsListView: View {
ToolbarTitleMenu { ToolbarTitleMenu {
Button { Button {
viewModel.selectedType = nil viewModel.selectedType = nil
Task {
await viewModel.fetchNotifications()
}
} label: { } label: {
Label("notifications.navigation-title", systemImage: "bell.fill") Label("notifications.navigation-title", systemImage: "bell.fill")
} }
@ -71,6 +73,9 @@ public struct NotificationsListView: View {
ForEach(Notification.NotificationType.allCases, id: \.self) { type in ForEach(Notification.NotificationType.allCases, id: \.self) { type in
Button { Button {
viewModel.selectedType = type viewModel.selectedType = type
Task {
await viewModel.fetchNotifications()
}
} label: { } label: {
Label { Label {
Text(type.menuTitle()) Text(type.menuTitle())
@ -87,14 +92,18 @@ public struct NotificationsListView: View {
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor) .background(theme.primaryBackgroundColor)
#endif #endif
.task { .onAppear {
viewModel.client = client viewModel.client = client
viewModel.currentAccount = account viewModel.currentAccount = account
if let lockedType { if let lockedType {
viewModel.isLockedType = true viewModel.isLockedType = true
viewModel.selectedType = lockedType viewModel.selectedType = lockedType
} else {
viewModel.loadSelectedType()
}
Task {
await viewModel.fetchNotifications()
} }
await viewModel.fetchNotifications()
} }
.refreshable { .refreshable {
SoundEffectManager.shared.playSound(.pull) SoundEffectManager.shared.playSound(.pull)

View file

@ -50,15 +50,10 @@ import SwiftUI
} }
consolidatedNotifications = [] consolidatedNotifications = []
Task {
await fetchNotifications()
}
} }
} }
func loadSelectedType() { func loadSelectedType() {
client = client
guard let value = UserDefaults.standard.string(forKey: filterKey) guard let value = UserDefaults.standard.string(forKey: filterKey)
else { else {
selectedType = nil selectedType = nil