view changes, added more obvious buttons, add relay in same view

This commit is contained in:
ericholguin
2023-03-23 23:52:47 -06:00
parent 14f71f1a1d
commit dfc397337b
3 changed files with 132 additions and 54 deletions

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "bitcoin-logo.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20px" height="20px" viewBox="0 0 20 20" version="1.1">
<g id="surface1">
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(96.078431%,70.196078%,0%);fill-opacity:1;" d="M 19.8125 10 C 19.8125 15.386719 15.378906 19.753906 9.90625 19.753906 C 4.433594 19.753906 0 15.386719 0 10 C 0 4.613281 4.433594 0.246094 9.90625 0.246094 C 15.378906 0.246094 19.8125 4.613281 19.8125 10 Z M 19.8125 10 "/>
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 7.21875 5.015625 C 7.5625 5.109375 7.90625 5.167969 8.25 5.261719 C 8.59375 5.355469 8.9375 5.414062 9.28125 5.507812 C 9.375 5.539062 9.40625 5.507812 9.4375 5.414062 C 9.5625 4.890625 9.6875 4.398438 9.8125 3.875 C 9.84375 3.785156 9.875 3.753906 9.96875 3.785156 C 10.28125 3.875 10.5625 3.9375 10.875 4 C 10.96875 4.03125 10.96875 4.0625 10.9375 4.125 C 10.8125 4.617188 10.6875 5.136719 10.5625 5.628906 C 10.5625 5.660156 10.5625 5.691406 10.53125 5.753906 C 10.78125 5.816406 11.0625 5.875 11.3125 5.9375 C 11.34375 5.9375 11.375 5.875 11.40625 5.847656 C 11.5 5.445312 11.59375 5.078125 11.71875 4.675781 L 11.8125 4.308594 C 11.8125 4.246094 11.84375 4.214844 11.90625 4.246094 C 12.21875 4.339844 12.53125 4.398438 12.875 4.492188 C 12.90625 4.492188 12.90625 4.523438 12.9375 4.523438 C 12.84375 4.921875 12.75 5.292969 12.65625 5.660156 C 12.625 5.816406 12.59375 5.96875 12.53125 6.125 C 12.5 6.214844 12.53125 6.246094 12.625 6.277344 L 13.65625 6.738281 C 13.96875 6.921875 14.25 7.167969 14.46875 7.476562 C 14.75 7.9375 14.78125 8.429688 14.65625 8.921875 C 14.5625 9.261719 14.4375 9.570312 14.1875 9.816406 C 14 10 13.75 10.125 13.5 10.214844 C 13.46875 10.214844 13.4375 10.246094 13.375 10.246094 C 13.5 10.339844 13.625 10.398438 13.75 10.492188 C 14.125 10.769531 14.375 11.109375 14.5 11.539062 C 14.5625 11.875 14.53125 12.246094 14.4375 12.585938 C 14.3125 13.015625 14.15625 13.382812 13.875 13.722656 C 13.53125 14.125 13.09375 14.339844 12.59375 14.398438 C 11.9375 14.492188 11.3125 14.429688 10.6875 14.339844 C 10.59375 14.308594 10.53125 14.339844 10.5 14.429688 C 10.375 14.921875 10.25 15.445312 10.125 15.9375 C 10.09375 16.0625 10.09375 16.09375 9.9375 16.03125 C 9.65625 15.96875 9.34375 15.875 9.0625 15.816406 C 8.96875 15.785156 8.96875 15.753906 9 15.691406 C 9.125 15.167969 9.25 14.644531 9.40625 14.152344 C 9.40625 14.09375 9.4375 14.0625 9.375 14.03125 C 9.125 13.96875 8.875 13.90625 8.59375 13.847656 C 8.53125 14.125 8.4375 14.398438 8.375 14.675781 C 8.3125 14.953125 8.21875 15.230469 8.15625 15.507812 C 8.125 15.570312 8.125 15.601562 8.03125 15.570312 C 7.71875 15.476562 7.40625 15.414062 7.09375 15.355469 C 7 15.324219 7 15.292969 7.03125 15.230469 C 7.15625 14.707031 7.28125 14.183594 7.4375 13.691406 C 7.4375 13.660156 7.46875 13.628906 7.46875 13.570312 C 6.75 13.382812 6.03125 13.199219 5.28125 13.015625 C 5.34375 12.890625 5.375 12.800781 5.4375 12.675781 C 5.5625 12.398438 5.6875 12.125 5.78125 11.875 C 5.8125 11.785156 5.84375 11.785156 5.9375 11.785156 C 6.15625 11.847656 6.40625 11.90625 6.625 11.9375 C 6.875 12 7.0625 11.875 7.09375 11.660156 C 7.5 10.09375 7.90625 8.523438 8.28125 6.921875 C 8.34375 6.675781 8.1875 6.398438 7.90625 6.308594 C 7.625 6.214844 7.34375 6.152344 7.09375 6.09375 C 7.03125 6.09375 7 6.0625 7.03125 6 C 7.125 5.660156 7.21875 5.292969 7.3125 4.953125 C 7.1875 5.046875 7.1875 5.046875 7.21875 5.015625 Z M 8.8125 12.617188 C 8.84375 12.617188 8.875 12.644531 8.875 12.644531 C 9.375 12.769531 9.90625 12.921875 10.4375 12.953125 C 10.8125 12.984375 11.15625 12.984375 11.5 12.863281 C 12.09375 12.675781 12.34375 11.90625 12 11.414062 C 11.84375 11.167969 11.59375 11.015625 11.34375 10.863281 C 10.78125 10.554688 10.125 10.429688 9.5 10.308594 C 9.40625 10.277344 9.40625 10.308594 9.375 10.398438 C 9.3125 10.707031 9.21875 10.984375 9.15625 11.292969 C 9.03125 11.722656 8.9375 12.152344 8.8125 12.617188 Z M 11.4375 9.476562 C 11.5 9.476562 11.65625 9.445312 11.78125 9.414062 C 12.375 9.292969 12.6875 8.617188 12.375 8.09375 C 12.21875 7.816406 11.9375 7.628906 11.65625 7.507812 C 11.21875 7.324219 10.78125 7.230469 10.3125 7.109375 C 10.21875 7.078125 10.1875 7.109375 10.15625 7.199219 C 10 7.847656 9.84375 8.460938 9.65625 9.109375 C 9.625 9.167969 9.65625 9.199219 9.71875 9.230469 C 9.84375 9.261719 9.9375 9.292969 10.0625 9.324219 C 10.53125 9.382812 10.9375 9.476562 11.4375 9.476562 Z M 11.4375 9.476562 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -10,8 +10,8 @@ import SwiftUI
struct RelayConfigView: View {
let state: DamusState
@State var new_relay: String = ""
@State var show_add_relay: Bool = false
@State var relays: [RelayDescriptor]
@State private var showActionButtons = false
@Environment(\.dismiss) var dismiss
@@ -37,72 +37,122 @@ struct RelayConfigView: View {
.onReceive(handle_notify(.switched_timeline)) { _ in
dismiss()
}
.sheet(isPresented: $show_add_relay) {
AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { m_relay in
guard var relay = m_relay else {
return
}
if relay.starts(with: "wss://") == false && relay.starts(with: "ws://") == false {
relay = "wss://" + relay
}
if relay.hasSuffix("/") {
relay.removeLast();
}
guard let url = URL(string: relay) else {
return
}
guard let ev = state.contacts.event else {
return
}
guard let privkey = state.keypair.privkey else {
return
}
let info = RelayInfo.rw
guard (try? state.pool.add_relay(url, info: info)) != nil else {
return
}
state.pool.connect(to: [relay])
guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: relay, info: info) else {
return
}
process_contact_event(state: state, ev: ev)
state.pool.send(.event(new_ev))
}
}
}
var MainContent: some View {
Form {
Section {
List(Array(relays), id: \.url) { relay in
RelayView(state: state, relay: relay.url.absoluteString)
}
AddRelayView(relay: $new_relay)
} header: {
HStack {
Text("Relays", comment: "Header text for relay server list for configuration.")
Spacer()
Button(action: { show_add_relay = true }) {
Image(systemName: "plus")
.foregroundColor(.accentColor)
Text(NSLocalizedString("Connect To Relay", comment: "Label for section for adding a relay server."))
.font(.system(size: 18, weight: .heavy))
.padding(.bottom, 5)
}
} footer: {
VStack {
HStack {
Spacer()
if(!new_relay.isEmpty) {
Button(NSLocalizedString("Cancel", comment: "Button to cancel out of view adding user inputted relay.")) {
new_relay = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
.font(.system(size: 14, weight: .bold))
.frame(width: 80, height: 30)
.foregroundColor(.white)
.background(LINEAR_GRADIENT)
.clipShape(Capsule())
.padding(EdgeInsets(top: 15, leading: 0, bottom: 0, trailing: 0))
Button(NSLocalizedString("Add", comment: "Button to confirm adding user inputted relay.")) {
if new_relay.starts(with: "wss://") == false && new_relay.starts(with: "ws://") == false {
new_relay = "wss://" + new_relay
}
if new_relay.hasSuffix("/") {
new_relay.removeLast();
}
guard let url = URL(string: new_relay) else {
return
}
guard let ev = state.contacts.event else {
return
}
guard let privkey = state.keypair.privkey else {
return
}
let info = RelayInfo.rw
guard (try? state.pool.add_relay(url, info: info)) != nil else {
return
}
state.pool.connect(to: [new_relay])
guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: new_relay, info: info) else {
return
}
process_contact_event(state: state, ev: ev)
state.pool.send(.event(new_ev))
new_relay = ""
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
.font(.system(size: 14, weight: .bold))
.frame(width: 80, height: 30)
.foregroundColor(.white)
.background(LINEAR_GRADIENT)
.clipShape(Capsule())
.padding(EdgeInsets(top: 15, leading: 0, bottom: 0, trailing: 0))
}
}
}
}
Section {
List(Array(relays), id: \.url) { relay in
RelayView(state: state, relay: relay.url.absoluteString, showActionButtons: $showActionButtons)
}
} header: {
HStack {
Text(NSLocalizedString("Connected Relays", comment: "Section title for relay servers that are connected."))
.font(.system(size: 18, weight: .heavy))
.padding(.bottom, 5)
}
}
if recommended.count > 0 {
Section(NSLocalizedString("Recommended Relays", comment: "Section title for recommend relay servers that could be added as part of configuration")) {
Section {
List(recommended, id: \.url) { r in
RecommendedRelayView(damus: state, relay: r.url.absoluteString)
RecommendedRelayView(damus: state, relay: r.url.absoluteString, showActionButtons: $showActionButtons)
}
} header: {
Text(NSLocalizedString("Recommended Relays", comment: "Section title for recommend relay servers that could be added as part of configuration"))
.font(.system(size: 18, weight: .heavy))
.padding(.bottom, 5)
}
}
}
.navigationTitle(NSLocalizedString("Relays", comment: "Title of relays view"))
.navigationBarTitleDisplayMode(.large)
.toolbar {
if state.keypair.privkey != nil {
if showActionButtons {
Button("Done") {
showActionButtons.toggle()
}
} else {
Button("Edit") {
showActionButtons.toggle()
}
}
}