Skip to content

Commit

Permalink
Add timer for sub.club account
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Aug 15, 2024
1 parent 8c6d2be commit 83bf872
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Packages/Account/Sources/Account/AccountDetailHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 83bf872

Please sign in to comment.