2021-08-31 21:17:50 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct UnsubscribeAlertModifier: ViewModifier {
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-08-31 21:17:50 +00:00
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
2021-09-25 08:18:22 +00:00
|
|
|
.alert(unsubscribeAlertTitle, isPresented: $navigation.presentingUnsubscribeAlert) {
|
|
|
|
if let channel = navigation.channelToUnsubscribe {
|
2021-08-31 21:17:50 +00:00
|
|
|
Button("Unsubscribe", role: .destructive) {
|
2021-09-19 11:06:54 +00:00
|
|
|
subscriptions.unsubscribe(channel.id)
|
2021-08-31 21:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var unsubscribeAlertTitle: String {
|
2021-09-25 08:18:22 +00:00
|
|
|
if let channel = navigation.channelToUnsubscribe {
|
2021-08-31 21:17:50 +00:00
|
|
|
return "Unsubscribe from \(channel.name)"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown channel"
|
|
|
|
}
|
|
|
|
}
|