commit 45ab394b09a958e2f89bde17bd24e8364b81c453
parent 47e750557388820cd2ea7c1fad425fa4de829726
Author: Bryan Montz <bryanmontz@me.com>
Date: Sat, 15 Jul 2023 07:48:06 -0500
fixed: relay detail view is not immediately available after adding new relay
Changelog-Fixed: relay detail view is not immediately available after adding new relay
Closes: https://github.com/damus-io/damus/issues/1369
Signed-off-by: Bryan Montz <bryanmontz@me.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/damus/Util/Relays/RelayModelCache.swift b/damus/Util/Relays/RelayModelCache.swift
@@ -7,7 +7,7 @@
import Foundation
-final class RelayModelCache {
+final class RelayModelCache: ObservableObject {
private var models = [RelayURL: RelayModel]()
func model(withURL url: RelayURL) -> RelayModel? {
@@ -23,5 +23,6 @@ final class RelayModelCache {
func insert(model: RelayModel) {
models[model.url] = model
+ objectWillChange.send()
}
}
diff --git a/damus/Views/Relays/RelayView.swift b/damus/Views/Relays/RelayView.swift
@@ -10,9 +10,17 @@ import SwiftUI
struct RelayView: View {
let state: DamusState
let relay: String
+ @ObservedObject private var model_cache: RelayModelCache
@Binding var showActionButtons: Bool
+ init(state: DamusState, relay: String, showActionButtons: Binding<Bool>) {
+ self.state = state
+ self.relay = relay
+ self.model_cache = state.relay_model_cache
+ _showActionButtons = showActionButtons
+ }
+
var body: some View {
Group {
HStack {
@@ -27,7 +35,7 @@ struct RelayView: View {
RelayType(is_paid: state.relay_model_cache.model(with_relay_id: relay)?.metadata.is_paid ?? false)
- if let meta = state.relay_model_cache.model(with_relay_id: relay)?.metadata {
+ if let meta = model_cache.model(with_relay_id: relay)?.metadata {
Text(relay)
.background(
NavigationLink(value: Route.RelayDetail(relay: relay, metadata: meta), label: {