Skip to content

Commit

Permalink
Merge pull request #1741 from planetary-social/bdm/165-nip05-search
Browse files Browse the repository at this point in the history
fixed: while searching for users to add to a list, NIP-05 searches dismiss the view
  • Loading branch information
joshuatbrown authored Jan 24, 2025
2 parents f8311df + d093c2c commit a7975e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added view for managing users in a list. [#135](https://github.com/verse-pbc/issues/issues/135)
- Added ability to delete lists. [#136](https://github.com/verse-pbc/issues/issues/136)
- Added analytics for feed source selection and lists. [#129](https://github.com/verse-pbc/issues/issues/129)
- Fixed: while searching for users to add to a list, NIP-05 searches dismiss the view. [#165](https://github.com/verse-pbc/issues/issues/165)

### Internal Changes
- Added function for creating a new list and a test verifying list editing. [#112](https://github.com/verse-pbc/issues/issues/112)
Expand Down
28 changes: 21 additions & 7 deletions Nos/Controller/SearchController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum SearchOrigin {

/// Any and all authors in the search results. As of this writing, _only_ authors appear in search results,
/// so this contains all search results, period.
var authorResults = [Author]()
private(set) var authorResults = [Author]()

var state: SearchState = .noQuery

Expand All @@ -72,11 +72,15 @@ enum SearchOrigin {

/// The origin of the current search.
let searchOrigin: SearchOrigin

/// If true, will automatically trigger routing to detail views for exact matches of NIP-05s, npubs, and note ids.
let routesMatchesAutomatically: Bool

// MARK: - Init

init(searchOrigin: SearchOrigin = .discover) {
init(searchOrigin: SearchOrigin = .discover, routesMatchesAutomatically: Bool = true) {
self.searchOrigin = searchOrigin
self.routesMatchesAutomatically = routesMatchesAutomatically

queryPublisher
.removeDuplicates()
Expand Down Expand Up @@ -255,17 +259,27 @@ enum SearchOrigin {
Task(priority: .userInitiated) {
if let publicKeyHex = await relayService.retrievePublicKeyFromUsername(trimmedQuery) {
Task { @MainActor in
analytics.displayedAuthorFromDiscoverSearch(resultsCount: 1)
router.pushAuthor(id: publicKeyHex)
if let author = try? Author.findOrCreate(by: publicKeyHex, context: context) {
if routesMatchesAutomatically {
analytics.displayedAuthorFromDiscoverSearch(resultsCount: 1)
router.push(author)
} else {
authorResults = [author]
}
}
}
}
}
} else if let author = author(fromPublicKey: trimmedQuery) {
Task { @MainActor in
analytics.displayedAuthorFromDiscoverSearch(resultsCount: 1)
router.push(author)
if routesMatchesAutomatically {
analytics.displayedAuthorFromDiscoverSearch(resultsCount: 1)
router.push(author)
} else {
authorResults = [author]
}
}
} else if let note = note(fromPublicKey: trimmedQuery) {
} else if routesMatchesAutomatically, let note = note(fromPublicKey: trimmedQuery) {
Task { @MainActor in
analytics.displayedNoteFromDiscoverSearch()
router.push(note)
Expand Down
8 changes: 7 additions & 1 deletion Nos/Views/Components/Author/AuthorSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct AuthorSearchView<EmptyPlaceholder: View>: View {
isModal: Bool,
avatarOverlayMode: AvatarOverlayMode = .follows,
relatedAuthors: [Author]? = nil,
routesMatchesAutomatically: Bool = true,
@ViewBuilder emptyPlaceholder: @escaping () -> EmptyPlaceholder? = { nil },
didSelectGesture: ((Author) -> Void)? = nil
) {
Expand All @@ -39,7 +40,12 @@ struct AuthorSearchView<EmptyPlaceholder: View>: View {
self.relatedAuthors = relatedAuthors
self.didSelectGesture = didSelectGesture
self.emptyPlaceholder = emptyPlaceholder
_searchController = State(initialValue: SearchController(searchOrigin: searchOrigin))
_searchController = State(
initialValue: SearchController(
searchOrigin: searchOrigin,
routesMatchesAutomatically: routesMatchesAutomatically
)
)
}

var body: some View {
Expand Down
1 change: 1 addition & 0 deletions Nos/Views/Lists/AuthorListManageUsersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct AuthorListManageUsersView: View {
searchOrigin: .lists,
isModal: false,
avatarOverlayMode: .inSet(authors: authors),
routesMatchesAutomatically: false,
emptyPlaceholder: {
AuthorsView(
authors: Array(authors),
Expand Down

0 comments on commit a7975e9

Please sign in to comment.