1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

relays: remove usage of show action button binding

This commit is contained in:
ericholguin 2023-09-10 22:22:24 -06:00 committed by William Casarin
parent c4dfae9ede
commit fff4549933
2 changed files with 63 additions and 40 deletions

View File

@ -11,17 +11,16 @@ struct RecommendedRelayView: View {
let damus: DamusState
let relay: String
let add_button: Bool
let user_recommended: Bool
@ObservedObject private var model_cache: RelayModelCache
@Binding var showActionButtons: Bool
init(damus: DamusState, relay: String, add_button: Bool = true, showActionButtons: Binding<Bool>) {
init(damus: DamusState, relay: String, add_button: Bool = true, user_recommended: Bool = false) {
self.damus = damus
self.relay = relay
self.add_button = add_button
self.user_recommended = user_recommended
self.model_cache = damus.relay_model_cache
self._showActionButtons = showActionButtons
}
var recommended: [RelayDescriptor] {
@ -34,28 +33,65 @@ struct RecommendedRelayView: View {
}
var body: some View {
VStack {
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)
}
let meta = model_cache.model(with_relay_id: relay)?.metadata
if user_recommended {
HStack {
Text(meta?.name ?? relay.hostname ?? relay)
.lineLimit(1)
RelayPicView(relay: relay, icon: meta?.icon, size: 50, highlight: .none, disable_animation: false)
.padding(.horizontal, 5)
VStack(alignment: .leading) {
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)
}
}
.contextMenu {
CopyAction(relay: relay)
}
if let keypair = damus.keypair.to_full() {
AddButton(keypair: keypair)
} 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 {
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)
}
}

View File

@ -12,7 +12,6 @@ struct UserRelaysView: View {
let relays: [String]
@State var relay_state: [(String, Bool)]
@State private var showAddButton = false
init(state: DamusState, relays: [String]) {
self.state = state
@ -29,25 +28,13 @@ struct UserRelaysView: View {
var body: some View {
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
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."))
.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()
}
}
}
}
}
}