diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 5cdd6592..e21b60fd 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -95,7 +95,12 @@ struct ContentView: View { var body: some View { NavigationView { VStack { - TopBar(selected: self.timeline) + if self.loading { + ProgressView() + .progressViewStyle(.circular) + .padding([.bottom], 4) + } + ZStack { if let pool = self.pool { MainContent(pool: pool) @@ -103,6 +108,7 @@ struct ContentView: View { } PostButtonContainer } + TopBar(selected: self.timeline ?? .friends) } .navigationBarTitle("Damus", displayMode: .inline) } @@ -220,14 +226,14 @@ struct ContentView: View { switch ev { case .connected: + self.loading = ((self.pool?.num_connecting ?? 0) > 0) send_filters(relay_id: relay_id) case .error(let merr): let desc = merr.debugDescription if desc.contains("Software caused connection abort") { self.pool?.reconnect(to: [relay_id]) } - case .disconnected: - self.pool?.reconnect(to: [relay_id]) + case .disconnected: fallthrough case .cancelled: self.pool?.reconnect(to: [relay_id]) case .reconnectSuggested(let t): @@ -248,10 +254,6 @@ struct ContentView: View { return } - if self.loading { - self.loading = false - } - if has_events[ev.id] == nil { has_events[ev.id] = () let last_k = last_event_of_kind[ev.kind] diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift index ad5dba5a..744568f6 100644 --- a/damus/Nostr/RelayPool.swift +++ b/damus/Nostr/RelayPool.swift @@ -35,6 +35,10 @@ class RelayPool { var descriptors: [RelayDescriptor] { relays.map { $0.descriptor } } + + var num_connecting: Int { + return relays.reduce(0) { n, r in n + (r.connection.isConnecting ? 1 : 0) } + } func remove_handler(sub_id: String) { handlers = handlers.filter { $0.sub_id != sub_id }