From 70b55ec2b2e38227fdeb4b73d4ac537e488247fd Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 26 Mar 2022 19:01:38 +0100 Subject: [PATCH] Further subscribe buttons improvements --- Shared/Player/VideoDetails.swift | 22 +++++++++++++++------- Shared/Views/ChannelVideosView.swift | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index 895a371c..832e6443 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -12,6 +12,7 @@ struct VideoDetails: View { @Binding var fullScreen: Bool @State private var subscribed = false + @State private var subscriptionToggleButtonDisabled = false @State private var presentingUnsubscribeAlert = false @State private var presentingAddToPlaylist = false @State private var presentingShareSheet = false @@ -254,10 +255,13 @@ struct VideoDetails: View { "Are you sure you want to unsubscribe from \(video!.channel.name)?" ), primaryButton: .destructive(Text("Unsubscribe")) { - subscriptions.unsubscribe(video!.channel.id) + subscriptionToggleButtonDisabled = true - withAnimation { - subscribed.toggle() + subscriptions.unsubscribe(video!.channel.id) { + withAnimation { + subscriptionToggleButtonDisabled = false + subscribed.toggle() + } } }, secondaryButton: .cancel() @@ -265,16 +269,20 @@ struct VideoDetails: View { } } else { Button("Subscribe") { - subscriptions.subscribe(video!.channel.id) + subscriptionToggleButtonDisabled = true - withAnimation { - subscribed.toggle() + subscriptions.subscribe(video!.channel.id) { + withAnimation { + subscriptionToggleButtonDisabled = false + subscribed.toggle() + } } } .backport - .tint(.blue) + .tint(subscriptionToggleButtonDisabled ? .gray : .blue) } } + .disabled(subscriptionToggleButtonDisabled) .font(.system(size: 13)) .buttonStyle(.borderless) } diff --git a/Shared/Views/ChannelVideosView.swift b/Shared/Views/ChannelVideosView.swift index f680f0bb..4dc384a1 100644 --- a/Shared/Views/ChannelVideosView.swift +++ b/Shared/Views/ChannelVideosView.swift @@ -150,7 +150,7 @@ struct ChannelVideosView: View { subscriptionToggleButtonDisabled = true subscriptions.unsubscribe(channel.id) { - self.subscriptionToggleButtonDisabled = false + subscriptionToggleButtonDisabled = false } } } else {