This commit is contained in:
Thomas Ricouard 2024-06-11 21:38:24 +02:00
parent 7cf0020729
commit dbc9c1f930
3 changed files with 17 additions and 17 deletions

View file

@ -219,7 +219,7 @@ struct AccountDetailHeaderView: View {
.accessibilityRespondsToUserInteraction(false) .accessibilityRespondsToUserInteraction(false)
movedToView movedToView
joinedAtView joinedAtView
if viewModel.isProAccount { if viewModel.isProAccount && viewModel.relationship?.following == false {
tipView tipView
} }
} }
@ -328,7 +328,7 @@ struct AccountDetailHeaderView: View {
try? await viewModel.followButtonViewModel?.follow() try? await viewModel.followButtonViewModel?.follow()
} }
} label: { } label: {
Text("$ Send tip") Text("$ Subscribe")
} }
.buttonStyle(.bordered) .buttonStyle(.bordered)
.padding(.top, 8) .padding(.top, 8)

View file

@ -30,8 +30,7 @@ import SwiftUI
func follow() async throws { func follow() async throws {
guard let client else { return } guard let client else { return }
do { do {
_ = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false, reblogs: true)) relationship = try await client.post(endpoint: Accounts.follow(id: accountId, notify: false, reblogs: true))
try await refreshRelationship()
relationshipUpdated(relationship) relationshipUpdated(relationship)
} catch { } catch {
throw error throw error
@ -41,8 +40,7 @@ import SwiftUI
func unfollow() async throws { func unfollow() async throws {
guard let client else { return } guard let client else { return }
do { do {
_ = try await client.post(endpoint: Accounts.unfollow(id: accountId)) relationship = try await client.post(endpoint: Accounts.unfollow(id: accountId))
try await refreshRelationship()
relationshipUpdated(relationship) relationshipUpdated(relationship)
} catch { } catch {
throw error throw error
@ -54,6 +52,7 @@ import SwiftUI
let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [accountId])) let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [accountId]))
if let relationship = relationships.first { if let relationship = relationships.first {
self.relationship = relationship self.relationship = relationship
relationshipUpdated(relationship)
} }
} }

View file

@ -7,14 +7,15 @@ import AppAccount
@MainActor @MainActor
struct TipSheetView: View { struct TipSheetView: View {
private let tips = ["$2.00", "$5.00", "$10.00", "$15.00", "$15.00", "$20.00", "$50.00"] private let tips = [200, 500, 1000]
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
@Environment(Theme.self) private var theme: Theme @Environment(Theme.self) private var theme: Theme
@Environment(TipedUsers.self) private var tipedUSers: TipedUsers @Environment(TipedUsers.self) private var tipedUSers: TipedUsers
@Environment(\.openURL) private var openURL @Environment(\.openURL) private var openURL
@Environment(AppAccountsManager.self) private var appAccount: AppAccountsManager @Environment(AppAccountsManager.self) private var appAccount: AppAccountsManager
@State private var selectedTip: String? @State private var selectedTip: Int?
private enum TipState: Int, Equatable { private enum TipState: Int, Equatable {
case selection, sending, sent case selection, sending, sent
@ -57,16 +58,16 @@ struct TipSheetView: View {
.padding(.top, 8) .padding(.top, 8)
} }
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text("Send a tip") Text("Subscribe")
.font(.title2) .font(.title2)
Text("Send a tip to @\(account.username) to get access to exclusive content!") Text("Subscribe to @\(account.username) to get access to exclusive content!")
WrappingHStack(tips, id: \.self, spacing: .constant(12)) { tip in WrappingHStack(tips, id: \.self, spacing: .constant(12)) { tip in
Button { Button {
withAnimation(.easeInOut(duration: 0.5)) { withAnimation(.easeInOut(duration: 0.5)) {
selectedTip = tip selectedTip = tip
} }
} label: { } label: {
Text(tip) Text((Double(tip) / 100.0).formatted(.currency(code: "USD").presentation(.narrow)))
} }
.buttonStyle(.bordered) .buttonStyle(.bordered)
.padding(.vertical, 8) .padding(.vertical, 8)
@ -80,9 +81,9 @@ struct TipSheetView: View {
Spacer() Spacer()
if let selectedTip { if selectedTip != nil {
HStack(alignment: .top) { HStack(alignment: .top) {
Text("Send \(selectedTip)") Text("Subscribe")
.font(.headline) .font(.headline)
.fontWeight(.bold) .fontWeight(.bold)
} }
@ -120,15 +121,15 @@ struct TipSheetView: View {
private var sentView: some View { private var sentView: some View {
VStack(alignment: .center) { VStack(alignment: .center) {
Text("🎉🤑🎉") Text("Almost there...")
Text("Thank for the tip!")
} }
.font(.title) .font(.title)
.fontWeight(.bold) .fontWeight(.bold)
.onAppear { .onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let accountName = appAccount.currentAccount.accountName, if let selectedTip,
let url = URL(string: "https://social-proxy.com/subscribe/to/\(account.username)?callback=icecubesapp://socialproxy&id=@\(accountName)") { let accountName = appAccount.currentAccount.accountName,
let url = URL(string: "https://social-proxy.com/subscribe/to/\(account.username)?callback=icecubesapp://socialproxy&id=@\(accountName)&amount=\(selectedTip)&currency=USD") {
openURL(url) openURL(url)
} }
} }