damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | LICENSE

commit 7ef9bc531e7327f884b177e3fff36ece01d4cc8b
parent dff12702f5bde31b753f9c60bb8302eea9f28fb3
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  6 Jun 2022 22:14:24 -0700

search working

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/ContentView.swift | 7+++----
Mdamus/Models/SearchHomeModel.swift | 5+----
Mdamus/Views/ProfileView.swift | 29++++++++++++++---------------
Mdamus/Views/SearchHomeView.swift | 3+++
Mdamus/Views/SearchResultsView.swift | 27++++++++++++++++++---------
5 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -332,11 +332,10 @@ struct ContentView: View { add_relay(pool, "wss://relay.damus.io") add_relay(pool, "wss://nostr-pub.wellorder.net") - add_relay(pool, "wss://nostr.onsats.org") - add_relay(pool, "wss://nostr.bitcoiner.social") + //add_relay(pool, "wss://nostr.bitcoiner.social") add_relay(pool, "ws://monad.jb55.com:8080") - add_relay(pool, "wss://nostr-relay.freeberty.net") - add_relay(pool, "wss://nostr-relay.untethr.me") + //add_relay(pool, "wss://nostr-relay.freeberty.net") + //add_relay(pool, "wss://nostr-relay.untethr.me") pool.register_handler(sub_id: sub_id, handler: home.handle_event) diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift @@ -13,7 +13,7 @@ class SearchHomeModel: ObservableObject { @Published var events: [NostrEvent] = [] let pool: RelayPool let sub_id = UUID().description - let limit: UInt32 = 1000 + let limit: UInt32 = 250 init(pool: RelayPool) { self.pool = pool @@ -44,9 +44,6 @@ class SearchHomeModel: ObservableObject { guard sub_id == self.sub_id else { return } - guard self.events.count <= limit else { - return - } if ev.kind == NostrKind.text.rawValue { let _ = insert_uniq_sorted_event(events: &events, new_ev: ev) { $0.created_at > $1.created_at diff --git a/damus/Views/ProfileView.swift b/damus/Views/ProfileView.swift @@ -84,12 +84,12 @@ struct ProfileView: View { Text(data?.about ?? "") - if let contact = profile.contacts { - Divider() + Divider() - let contacts = contact.referenced_pubkeys.map { $0.ref_id } - let following_model = FollowingModel(damus_state: damus_state, contacts: contacts) - HStack { + HStack { + if let contact = profile.contacts { + let contacts = contact.referenced_pubkeys.map { $0.ref_id } + let following_model = FollowingModel(damus_state: damus_state, contacts: contacts) NavigationLink(destination: FollowingView(damus_state: damus_state, following: following_model, whos: profile.pubkey)) { HStack { Text("\(profile.following)") @@ -98,18 +98,17 @@ struct ProfileView: View { } } .buttonStyle(PlainButtonStyle()) - - let fview = FollowersView(damus_state: damus_state, whos: profile.pubkey) - .environmentObject(followers) - NavigationLink(destination: fview) { - HStack { - Text("\(followers.contacts.count)") - Text("Followers") - .foregroundColor(.gray) - } + } + let fview = FollowersView(damus_state: damus_state, whos: profile.pubkey) + .environmentObject(followers) + NavigationLink(destination: fview) { + HStack { + Text("\(followers.contacts.count)") + Text("Followers") + .foregroundColor(.gray) } - .buttonStyle(PlainButtonStyle()) } + .buttonStyle(PlainButtonStyle()) } } } diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift @@ -53,6 +53,9 @@ struct SearchHomeView: View { MainContent } + .onChange(of: search) { s in + print("search change 1") + } .onAppear { model.subscribe() } diff --git a/damus/Views/SearchResultsView.swift b/damus/Views/SearchResultsView.swift @@ -17,11 +17,12 @@ struct SearchResultsView: View { } var MainContent: some View { - VStack { - ForEach(results, id: \.0) { prof in - ProfileSearchResult(pk: prof.0, res: prof.1) + ScrollView { + LazyVStack { + ForEach(results, id: \.0) { prof in + ProfileSearchResult(pk: prof.0, res: prof.1) + } } - Spacer() } } @@ -32,9 +33,11 @@ struct SearchResultsView: View { let prof = els.element.value.profile let lowname = prof.name.map { $0.lowercased() } let lowdisp = prof.display_name.map { $0.lowercased() } - let ok = new == pk || String(new.dropFirst()) == pk + let ok = new.count == 1 ? + ((lowname?.starts(with: new) ?? false) || + (lowdisp?.starts(with: new) ?? false)) : (pk.starts(with: new) || String(new.dropFirst()) == pk || lowname?.contains(new) ?? false - || lowdisp?.contains(new) ?? false + || lowdisp?.contains(new) ?? false) if ok { acc.append((pk, prof)) } @@ -45,13 +48,19 @@ struct SearchResultsView: View { var body: some View { MainContent .frame(maxHeight: .infinity) - .onChange(of: search) { new in search_changed(new) } + .onAppear { + search_changed(search) + } + .onChange(of: search) { new in + search_changed(new) + } } } +/* struct SearchResultsView_Previews: PreviewProvider { static var previews: some View { - let search = Binding<String>.init(get: { "jb55" }, set: { _ in }) - SearchResultsView(damus_state: test_damus_state(), search: search) + SearchResultsView(damus_state: test_damus_state(), s) } } + */