RelayStatusView.swift (2399B)
1 // 2 // RelayStatusView.swift 3 // damus 4 // 5 // Created by William Casarin on 2023-02-10. 6 // 7 8 import SwiftUI 9 10 struct RelayStatusView: View { 11 @ObservedObject var connection: RelayConnection 12 13 var body: some View { 14 Group { 15 if connection.isConnecting { 16 Text("Connecting", comment: "Relay status label that indicates a relay is connecting.") 17 .font(.caption) 18 .frame(height: 20) 19 .padding(.horizontal, 10) 20 .foregroundColor(DamusColors.warning) 21 .background(DamusColors.warningQuaternary) 22 .cornerRadius(20) 23 .overlay( 24 RoundedRectangle(cornerRadius: 20) 25 .stroke(DamusColors.warningBorder, lineWidth: 1) 26 ) 27 } else if connection.isConnected { 28 Text("Online", comment: "Relay status label that indicates a relay is connected.") 29 .font(.caption) 30 .frame(height: 20) 31 .padding(.horizontal, 10) 32 .foregroundColor(DamusColors.success) 33 .background(DamusColors.successQuaternary) 34 .cornerRadius(20) 35 .overlay( 36 RoundedRectangle(cornerRadius: 20) 37 .stroke(DamusColors.successBorder, lineWidth: 1) 38 ) 39 } else { 40 Text("Error", comment: "Relay status label that indicates a relay had an error when connecting") 41 .font(.caption) 42 .frame(height: 20) 43 .padding(.horizontal, 10) 44 .foregroundColor(DamusColors.danger) 45 .background(DamusColors.dangerQuaternary) 46 .border(DamusColors.dangerBorder) 47 .cornerRadius(20) 48 .overlay( 49 RoundedRectangle(cornerRadius: 20) 50 .stroke(DamusColors.dangerBorder, lineWidth: 1) 51 ) 52 } 53 } 54 } 55 } 56 57 struct RelayStatusView_Previews: PreviewProvider { 58 static var previews: some View { 59 let connection = test_damus_state.pool.get_relay(RelayURL("wss://relay.damus.io")!)!.connection 60 RelayStatusView(connection: connection) 61 } 62 }