From a4d62d295c79686c0989854bec89c0846f7cb006 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 26 Dec 2022 07:38:19 -0800 Subject: [PATCH] Only reload global view on pulldown refresh Changelog-Changed: Only reload global view on pulldown refresh --- damus/ContentView.swift | 5 ++++- damus/Models/SearchHomeModel.swift | 9 +++++---- damus/Views/SearchHomeView.swift | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index 9b05b38..4f772e8 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -68,6 +68,8 @@ struct ContentView: View { @State var thread_open: Bool = false @State var search_open: Bool = false @State var filter_state : FilterState = .posts_and_replies + + @StateObject var search: SearchHomeModel = SearchHomeModel() @StateObject var home: HomeModel = HomeModel() // connect retry timer @@ -133,7 +135,7 @@ struct ContentView: View { } switch selected_timeline { case .search: - SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!)) + SearchHomeView(damus_state: damus_state!, model: search) case .home: PostingTimelineView @@ -403,6 +405,7 @@ struct ContentView: View { dms: home.dms ) home.damus_state = self.damus_state! + search.damus_state = self.damus_state! pool.connect() } diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift index 9783c5c..7ce9825 100644 --- a/damus/Models/SearchHomeModel.swift +++ b/damus/Models/SearchHomeModel.swift @@ -10,17 +10,18 @@ import Foundation /// The data model for the SearchHome view, typically something global-like class SearchHomeModel: ObservableObject { - @Published var events: [NostrEvent] = [] + @Published var events: [NostrEvent] @Published var loading: Bool = false var seen_pubkey: Set = Set() - let damus_state: DamusState + var damus_state: DamusState let base_subid = UUID().description let profiles_subid = UUID().description let limit: UInt32 = 250 - init(damus_state: DamusState) { - self.damus_state = damus_state + init() { + self.events = [] + self.damus_state = .empty } func get_base_filter() -> NostrFilter { diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift index 71c3bfd..c14b1bc 100644 --- a/damus/Views/SearchHomeView.swift +++ b/damus/Views/SearchHomeView.swift @@ -10,7 +10,7 @@ import CryptoKit struct SearchHomeView: View { let damus_state: DamusState - @StateObject var model: SearchHomeModel + @ObservedObject var model: SearchHomeModel @State var search: String = "" var SearchInput: some View { @@ -95,12 +95,15 @@ struct SearchHomeView: View { } } +/* struct SearchHomeView_Previews: PreviewProvider { static var previews: some View { let state = test_damus_state() SearchHomeView( damus_state: state, - model: SearchHomeModel(damus_state: state) + model: SearchHomeModel() ) } } + +*/