relays: remove usage of show action button binding
This commit is contained in:
committed by
William Casarin
parent
c4dfae9ede
commit
fff4549933
@@ -11,17 +11,16 @@ struct RecommendedRelayView: View {
|
|||||||
let damus: DamusState
|
let damus: DamusState
|
||||||
let relay: String
|
let relay: String
|
||||||
let add_button: Bool
|
let add_button: Bool
|
||||||
|
let user_recommended: Bool
|
||||||
|
|
||||||
@ObservedObject private var model_cache: RelayModelCache
|
@ObservedObject private var model_cache: RelayModelCache
|
||||||
|
|
||||||
@Binding var showActionButtons: Bool
|
init(damus: DamusState, relay: String, add_button: Bool = true, user_recommended: Bool = false) {
|
||||||
|
|
||||||
init(damus: DamusState, relay: String, add_button: Bool = true, showActionButtons: Binding<Bool>) {
|
|
||||||
self.damus = damus
|
self.damus = damus
|
||||||
self.relay = relay
|
self.relay = relay
|
||||||
self.add_button = add_button
|
self.add_button = add_button
|
||||||
|
self.user_recommended = user_recommended
|
||||||
self.model_cache = damus.relay_model_cache
|
self.model_cache = damus.relay_model_cache
|
||||||
self._showActionButtons = showActionButtons
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var recommended: [RelayDescriptor] {
|
var recommended: [RelayDescriptor] {
|
||||||
@@ -34,28 +33,65 @@ struct RecommendedRelayView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
let meta = model_cache.model(with_relay_id: relay)?.metadata
|
||||||
let meta = model_cache.model(with_relay_id: relay)?.metadata
|
|
||||||
|
|
||||||
RelayPicView(relay: relay, icon: meta?.icon, size: 70, highlight: .none, disable_animation: false)
|
|
||||||
if let meta = damus.relay_model_cache.model(with_relay_id: relay)?.metadata {
|
|
||||||
NavigationLink(value: Route.RelayDetail(relay: relay, metadata: meta)){
|
|
||||||
EmptyView()
|
|
||||||
}
|
|
||||||
.opacity(0.0)
|
|
||||||
.disabled(showActionButtons)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if user_recommended {
|
||||||
HStack {
|
HStack {
|
||||||
Text(meta?.name ?? relay.hostname ?? relay)
|
RelayPicView(relay: relay, icon: meta?.icon, size: 50, highlight: .none, disable_animation: false)
|
||||||
.lineLimit(1)
|
.padding(.horizontal, 5)
|
||||||
}
|
|
||||||
.contextMenu {
|
|
||||||
CopyAction(relay: relay)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let keypair = damus.keypair.to_full() {
|
VStack(alignment: .leading) {
|
||||||
AddButton(keypair: keypair)
|
HStack {
|
||||||
|
Text(meta?.name ?? relay.hostname ?? relay)
|
||||||
|
.font(.headline)
|
||||||
|
.padding(.bottom, 2)
|
||||||
|
|
||||||
|
RelayType(is_paid: damus.relay_model_cache.model(with_relay_id: relay)?.metadata.is_paid ?? false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(relay)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if let keypair = damus.keypair.to_full() {
|
||||||
|
VStack(alignment: .center) {
|
||||||
|
if damus.pool.get_relay(relay) == nil {
|
||||||
|
AddButton(keypair: keypair)
|
||||||
|
} else {
|
||||||
|
Image(systemName: "checkmark.circle")
|
||||||
|
.resizable()
|
||||||
|
.frame(width: 30, height: 30)
|
||||||
|
.foregroundColor(DamusColors.success)
|
||||||
|
.padding(.trailing, 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
VStack {
|
||||||
|
RelayPicView(relay: relay, icon: meta?.icon, size: 70, highlight: .none, disable_animation: false)
|
||||||
|
if let meta = damus.relay_model_cache.model(with_relay_id: relay)?.metadata {
|
||||||
|
NavigationLink(value: Route.RelayDetail(relay: relay, metadata: meta)){
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
.opacity(0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Text(meta?.name ?? relay.hostname ?? relay)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
.contextMenu {
|
||||||
|
CopyAction(relay: relay)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let keypair = damus.keypair.to_full() {
|
||||||
|
AddButton(keypair: keypair)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +128,6 @@ struct RecommendedRelayView: View {
|
|||||||
|
|
||||||
struct RecommendedRelayView_Previews: PreviewProvider {
|
struct RecommendedRelayView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RecommendedRelayView(damus: test_damus_state(), relay: "wss://relay.damus.io", showActionButtons: .constant(false))
|
RecommendedRelayView(damus: test_damus_state(), relay: "wss://relay.damus.io", user_recommended: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ struct UserRelaysView: View {
|
|||||||
let relays: [String]
|
let relays: [String]
|
||||||
|
|
||||||
@State var relay_state: [(String, Bool)]
|
@State var relay_state: [(String, Bool)]
|
||||||
@State private var showAddButton = false
|
|
||||||
|
|
||||||
init(state: DamusState, relays: [String]) {
|
init(state: DamusState, relays: [String]) {
|
||||||
self.state = state
|
self.state = state
|
||||||
@@ -29,25 +28,13 @@ struct UserRelaysView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List(relay_state, id: \.0) { (r, add) in
|
List(relay_state, id: \.0) { (r, add) in
|
||||||
RecommendedRelayView(damus: state, relay: r, add_button: add, showActionButtons: $showAddButton)
|
RecommendedRelayView(damus: state, relay: r, add_button: add, user_recommended: true)
|
||||||
}
|
}
|
||||||
|
.listStyle(PlainListStyle())
|
||||||
.onReceive(handle_notify(.relays_changed)) { _ in
|
.onReceive(handle_notify(.relays_changed)) { _ in
|
||||||
self.relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: self.relays)
|
self.relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: self.relays)
|
||||||
}
|
}
|
||||||
.navigationBarTitle(NSLocalizedString("Relays", comment: "Navigation bar title that shows the list of relays for a user."))
|
.navigationBarTitle(NSLocalizedString("Relays", comment: "Navigation bar title that shows the list of relays for a user."))
|
||||||
.toolbar{
|
|
||||||
if state.keypair.privkey != nil {
|
|
||||||
if showAddButton {
|
|
||||||
Button(NSLocalizedString("Done", comment: "Button that, when tapped, will finish adding a different user's relays to your relay by hiding the + buttons next to the relays.")) {
|
|
||||||
showAddButton.toggle()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Button(NSLocalizedString("Show +", comment: "Button that, when tapped, will show + buttons next to a user's relays.")) {
|
|
||||||
showAddButton.toggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user