Add Enable All / Disable All menu to channel notifications settings

This commit is contained in:
Arkadiusz Fal
2026-02-12 07:55:56 +01:00
parent 0cfe365d4f
commit 4f954b7c9c
2 changed files with 52 additions and 0 deletions

View File

@@ -11354,6 +11354,28 @@
} }
} }
}, },
"settings.notifications.disableAll" : {
"comment" : "Button to disable notifications for all channels",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Disable All"
}
}
}
},
"settings.notifications.enableAll" : {
"comment" : "Button to enable notifications for all channels",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Enable All"
}
}
}
},
"settings.notifications.noSubscriptions.description" : { "settings.notifications.noSubscriptions.description" : {
"comment" : "Description when no subscriptions exist", "comment" : "Description when no subscriptions exist",
"localizations" : { "localizations" : {

View File

@@ -160,6 +160,7 @@ struct ManageChannelNotificationsView: View {
@State private var subscriptions: [Subscription] = [] @State private var subscriptions: [Subscription] = []
@State private var isLoading = false @State private var isLoading = false
@State private var errorMessage: String? @State private var errorMessage: String?
@State private var refreshID = UUID()
private var subscriptionService: SubscriptionService? { appEnvironment?.subscriptionService } private var subscriptionService: SubscriptionService? { appEnvironment?.subscriptionService }
@@ -194,17 +195,46 @@ struct ManageChannelNotificationsView: View {
ForEach(subscriptions, id: \.channelID) { subscription in ForEach(subscriptions, id: \.channelID) { subscription in
ChannelNotificationToggle(subscription: subscription) ChannelNotificationToggle(subscription: subscription)
} }
.id(refreshID)
} }
} }
.navigationTitle(String(localized: "settings.notifications.manageChannels.title")) .navigationTitle(String(localized: "settings.notifications.manageChannels.title"))
#if os(iOS) #if os(iOS)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
#endif #endif
.toolbar {
if !subscriptions.isEmpty {
ToolbarItem(placement: .primaryAction) {
Menu {
Button {
setAllNotifications(enabled: true)
} label: {
Label(String(localized: "settings.notifications.enableAll"), systemImage: "bell.fill")
}
Button {
setAllNotifications(enabled: false)
} label: {
Label(String(localized: "settings.notifications.disableAll"), systemImage: "bell.slash")
}
} label: {
Image(systemName: "ellipsis.circle")
}
}
}
}
.task { .task {
await loadSubscriptionsAsync() await loadSubscriptionsAsync()
} }
} }
private func setAllNotifications(enabled: Bool) {
guard let dataManager = appEnvironment?.dataManager else { return }
for subscription in subscriptions {
dataManager.setNotificationsEnabled(enabled, for: subscription.channelID)
}
refreshID = UUID()
}
/// Loads subscriptions from the current subscription account provider. /// Loads subscriptions from the current subscription account provider.
/// For local accounts, loads from DataManager. /// For local accounts, loads from DataManager.
/// For Invidious/Piped accounts, fetches from the respective API. /// For Invidious/Piped accounts, fetches from the respective API.