DamusPurpleAccountView.swift (5367B)
1 // 2 // DamusPurpleAccountView.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2024-01-26. 6 // 7 8 import SwiftUI 9 10 struct DamusPurpleAccountView: View { 11 var colorScheme: ColorScheme = .dark 12 let damus_state: DamusState 13 let account: DamusPurple.Account 14 let pfp_size: CGFloat = 90.0 15 16 var body: some View { 17 VStack { 18 ProfilePicView(pubkey: account.pubkey, size: pfp_size, highlight: .custom(Color.black.opacity(0.4), 1.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) 19 .background(Color.black.opacity(0.4).clipShape(Circle())) 20 .shadow(color: .black, radius: 10, x: 0.0, y: 5) 21 22 profile_name 23 24 if account.active { 25 active_account_badge 26 } 27 else { 28 inactive_account_badge 29 } 30 31 // TODO: Generalize this view instead of setting up dividers and paddings manually 32 VStack { 33 HStack { 34 Text("Expiry date", comment: "Label for Purple subscription expiry date") 35 Spacer() 36 let formattedDate = DateFormatter.localizedString(from: account.expiry, dateStyle: .short, timeStyle: .none) 37 Text(formattedDate) 38 } 39 .padding(.horizontal) 40 .padding(.top, 20) 41 42 Divider() 43 .padding(.horizontal) 44 .padding(.vertical, 10) 45 46 HStack { 47 Text("Account creation", comment: "Label for Purple account creation date") 48 Spacer() 49 let formattedDate = DateFormatter.localizedString(from: account.created_at, dateStyle: .short, timeStyle: .none) 50 Text(formattedDate) 51 } 52 .padding(.horizontal) 53 54 Divider() 55 .padding(.horizontal) 56 .padding(.vertical, 10) 57 58 HStack { 59 Text("Subscriber number", comment: "Label for Purple account subscriber number") 60 Spacer() 61 Text(verbatim: "#\(account.subscriber_number)") 62 } 63 .padding(.horizontal) 64 .padding(.bottom, 20) 65 } 66 .foregroundColor(.white.opacity(0.8)) 67 .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 12, style: .continuous)) 68 .padding() 69 } 70 } 71 72 var profile_name: some View { 73 let display_name = self.profile_display_name() 74 return HStack(alignment: .center, spacing: 5) { 75 Text(display_name) 76 .font(.title) 77 .bold() 78 .foregroundStyle(.white) 79 80 SupporterBadge( 81 percent: nil, 82 purple_account: account, 83 style: .full, 84 text_color: .white 85 ) 86 } 87 } 88 89 var active_account_badge: some View { 90 HStack(spacing: 3) { 91 Image("check-circle.fill") 92 .resizable() 93 .frame(width: 15, height: 15) 94 95 Text("Active account", comment: "Badge indicating user has an active Damus Purple account") 96 .font(.caption) 97 .bold() 98 } 99 .foregroundColor(Color.white) 100 .padding(.vertical, 3) 101 .padding(.horizontal, 8) 102 .background(PinkGradient) 103 .cornerRadius(30.0) 104 } 105 106 var inactive_account_badge: some View { 107 HStack(spacing: 3) { 108 Image("warning") 109 .resizable() 110 .frame(width: 15, height: 15) 111 112 Text("Expired account", comment: "Badge indicating user has an expired Damus Purple account") 113 .font(.caption) 114 .bold() 115 } 116 .foregroundColor(DamusColors.danger) 117 .padding(.vertical, 3) 118 .padding(.horizontal, 8) 119 .background(DamusColors.dangerTertiary) 120 .cornerRadius(30.0) 121 } 122 123 func profile_display_name() -> String { 124 let profile_txn: NdbTxn<ProfileRecord?>? = damus_state.profiles.lookup_with_timestamp(account.pubkey) 125 let profile: NdbProfile? = profile_txn?.unsafeUnownedValue?.profile 126 let display_name = DisplayName(profile: profile, pubkey: account.pubkey).displayName 127 return display_name 128 } 129 } 130 131 #Preview("Active") { 132 DamusPurpleAccountView( 133 damus_state: test_damus_state, 134 account: DamusPurple.Account( 135 pubkey: test_pubkey, 136 created_at: Date.now, 137 expiry: Date.init(timeIntervalSinceNow: 60 * 60 * 24 * 30), 138 subscriber_number: 7, 139 active: true, 140 attributes: [] 141 ) 142 ) 143 } 144 145 #Preview("Expired") { 146 DamusPurpleAccountView( 147 damus_state: test_damus_state, 148 account: DamusPurple.Account( 149 pubkey: test_pubkey, 150 created_at: Date.init(timeIntervalSinceNow: -60 * 60 * 24 * 37), 151 expiry: Date.init(timeIntervalSinceNow: -60 * 60 * 24 * 7), 152 subscriber_number: 7, 153 active: false, 154 attributes: [] 155 ) 156 ) 157 }