mirror of https://github.com/lukechilds/damus.git
Browse Source
Changelog-Added: Show relay connection status in config Signed-off-by: William Casarin <jb55@jb55.com>profile-edit
2 changed files with 70 additions and 20 deletions
@ -0,0 +1,69 @@ |
|||
// |
|||
// RelayView.swift |
|||
// damus |
|||
// |
|||
// Created by William Casarin on 2022-10-16. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct RelayView: View { |
|||
let state: DamusState |
|||
let ev: NostrEvent |
|||
let relay: String |
|||
|
|||
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect() |
|||
@State var conn_color: Color = .gray |
|||
|
|||
func update_connection_color() { |
|||
for relay in state.pool.relays { |
|||
if relay.id == self.relay { |
|||
let c = relay.connection |
|||
if c.isConnected { |
|||
conn_color = .green |
|||
} else if c.isConnecting || c.isReconnecting { |
|||
conn_color = .yellow |
|||
} else { |
|||
conn_color = .red |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
var body: some View { |
|||
HStack { |
|||
Circle() |
|||
.frame(width: 8.0, height: 8.0) |
|||
.foregroundColor(conn_color) |
|||
Text(relay) |
|||
} |
|||
.onReceive(timer) { _ in |
|||
update_connection_color() |
|||
} |
|||
.onAppear() { |
|||
update_connection_color() |
|||
} |
|||
.swipeActions { |
|||
if let privkey = state.keypair.privkey { |
|||
Button { |
|||
guard let new_ev = remove_relay( ev: ev, privkey: privkey, relay: relay) else { |
|||
return |
|||
} |
|||
|
|||
state.contacts.event = new_ev |
|||
state.pool.send(.event(new_ev)) |
|||
} label: { |
|||
Label("Delete", systemImage: "trash") |
|||
} |
|||
.tint(.red) |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
struct RelayView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
RelayView(state: test_damus_state(), ev: NostrEvent(content: "content", pubkey: "pk"), relay: "wss://relay.damus.io", conn_color: .red) |
|||
} |
|||
} |
Loading…
Reference in new issue