yattee/Shared/Modifiers/UnsubscribeAlertModifier.swift

27 lines
834 B
Swift
Raw Normal View History

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
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 {
Button("Unsubscribe", role: .destructive) {
2021-09-19 11:06:54 +00:00
subscriptions.unsubscribe(channel.id)
}
}
}
}
var unsubscribeAlertTitle: String {
2021-09-25 08:18:22 +00:00
if let channel = navigation.channelToUnsubscribe {
return "Unsubscribe from \(channel.name)"
}
return "Unknown channel"
}
}