Further subscribe buttons improvements

This commit is contained in:
Arkadiusz Fal 2022-03-26 19:01:38 +01:00
parent c14a4a153d
commit 70b55ec2b2
2 changed files with 16 additions and 8 deletions

View File

@ -12,6 +12,7 @@ struct VideoDetails: View {
@Binding var fullScreen: Bool @Binding var fullScreen: Bool
@State private var subscribed = false @State private var subscribed = false
@State private var subscriptionToggleButtonDisabled = false
@State private var presentingUnsubscribeAlert = false @State private var presentingUnsubscribeAlert = false
@State private var presentingAddToPlaylist = false @State private var presentingAddToPlaylist = false
@State private var presentingShareSheet = false @State private var presentingShareSheet = false
@ -254,10 +255,13 @@ struct VideoDetails: View {
"Are you sure you want to unsubscribe from \(video!.channel.name)?" "Are you sure you want to unsubscribe from \(video!.channel.name)?"
), ),
primaryButton: .destructive(Text("Unsubscribe")) { primaryButton: .destructive(Text("Unsubscribe")) {
subscriptions.unsubscribe(video!.channel.id) subscriptionToggleButtonDisabled = true
withAnimation { subscriptions.unsubscribe(video!.channel.id) {
subscribed.toggle() withAnimation {
subscriptionToggleButtonDisabled = false
subscribed.toggle()
}
} }
}, },
secondaryButton: .cancel() secondaryButton: .cancel()
@ -265,16 +269,20 @@ struct VideoDetails: View {
} }
} else { } else {
Button("Subscribe") { Button("Subscribe") {
subscriptions.subscribe(video!.channel.id) subscriptionToggleButtonDisabled = true
withAnimation { subscriptions.subscribe(video!.channel.id) {
subscribed.toggle() withAnimation {
subscriptionToggleButtonDisabled = false
subscribed.toggle()
}
} }
} }
.backport .backport
.tint(.blue) .tint(subscriptionToggleButtonDisabled ? .gray : .blue)
} }
} }
.disabled(subscriptionToggleButtonDisabled)
.font(.system(size: 13)) .font(.system(size: 13))
.buttonStyle(.borderless) .buttonStyle(.borderless)
} }

View File

@ -150,7 +150,7 @@ struct ChannelVideosView: View {
subscriptionToggleButtonDisabled = true subscriptionToggleButtonDisabled = true
subscriptions.unsubscribe(channel.id) { subscriptions.unsubscribe(channel.id) {
self.subscriptionToggleButtonDisabled = false subscriptionToggleButtonDisabled = false
} }
} }
} else { } else {