2021-09-01 02:47:50 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct UnsubscribeAlertModifier: ViewModifier {
|
2021-09-25 13:48:22 +05:30
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-09-01 02:47:50 +05:30
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
2021-09-25 13:48:22 +05:30
|
|
|
.alert(unsubscribeAlertTitle, isPresented: $navigation.presentingUnsubscribeAlert) {
|
|
|
|
if let channel = navigation.channelToUnsubscribe {
|
2021-09-01 02:47:50 +05:30
|
|
|
Button("Unsubscribe", role: .destructive) {
|
2021-09-19 16:36:54 +05:30
|
|
|
subscriptions.unsubscribe(channel.id)
|
2021-09-01 02:47:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var unsubscribeAlertTitle: String {
|
2021-09-25 13:48:22 +05:30
|
|
|
if let channel = navigation.channelToUnsubscribe {
|
2021-09-01 02:47:50 +05:30
|
|
|
return "Unsubscribe from \(channel.name)"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown channel"
|
|
|
|
}
|
|
|
|
}
|