2021-09-01 02:47:50 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct UnsubscribeAlertModifier: ViewModifier {
|
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
|
|
|
@EnvironmentObject<Subscriptions> private var subscriptions
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
|
|
|
.alert(unsubscribeAlertTitle, isPresented: $navigationState.presentingUnsubscribeAlert) {
|
|
|
|
if let channel = navigationState.channelToUnsubscribe {
|
|
|
|
Button("Unsubscribe", role: .destructive) {
|
|
|
|
subscriptions.unsubscribe(channel.id) {
|
|
|
|
navigationState.openChannel(channel)
|
2021-09-14 02:11:16 +05:30
|
|
|
navigationState.tabSelection = .channel(channel.id)
|
2021-09-01 02:47:50 +05:30
|
|
|
navigationState.sidebarSectionChanged.toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var unsubscribeAlertTitle: String {
|
|
|
|
if let channel = navigationState.channelToUnsubscribe {
|
|
|
|
return "Unsubscribe from \(channel.name)"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown channel"
|
|
|
|
}
|
|
|
|
}
|