From 83bf872cca5e1c79a6ed3fa81ecb1ea46d903cb8 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 15 Aug 2024 21:25:04 +0200 Subject: [PATCH] Add timer for sub.club account --- .../Sources/Account/AccountDetailHeaderView.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift index 3d10e467..e1cba161 100644 --- a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift +++ b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift @@ -24,6 +24,8 @@ struct AccountDetailHeaderView: View { let account: Account let scrollViewProxy: ScrollViewProxy? + private let premiumTimer = Timer.publish(every: 5, on: .main, in: .common).autoconnect() + @State private var shouldListenToPremiumTimer: Bool = false @State private var isTipSheetPresented: Bool = false var body: some View { @@ -61,6 +63,17 @@ struct AccountDetailHeaderView: View { } } } + .onReceive(premiumTimer) { _ in + if shouldListenToPremiumTimer { + Task { + if viewModel.account?.isLinkedToPremiumAccount == true { + await viewModel.fetchAccount() + } else{ + try? await viewModel.followButtonViewModel?.refreshRelationship() + } + } + } + } } private var headerImageView: some View { @@ -332,6 +345,7 @@ struct AccountDetailHeaderView: View { private var tipView: some View { Button { isTipSheetPresented = true + shouldListenToPremiumTimer = true Task { if viewModel.account?.isLinkedToPremiumAccount == true { try? await viewModel.followPremiumAccount()