feat: Display up to 5 matching contacts during search#2863
feat: Display up to 5 matching contacts during search#2863
Conversation
|
Failed to generate code suggestions for PR |
PR Reviewer Guide 🔍(Review updated until commit 239353b)Here are some key observations to aid the review process:
|
|
Failed to generate code suggestions for PR |
c67044e to
5fabd6a
Compare
|
Persistent review updated to latest commit 5fabd6a |
|
Failed to generate code suggestions for PR |
|
Persistent review updated to latest commit 3509caa |
|
Persistent review updated to latest commit 01d14c1 |
|
Failed to generate code suggestions for PR |
|
Persistent review updated to latest commit 1e00265 |
|
Failed to generate code suggestions for PR |
|
Persistent review updated to latest commit ef31a79 |
|
Failed to generate code suggestions for PR |
1 similar comment
|
Failed to generate code suggestions for PR |
|
Persistent review updated to latest commit 715fdce |
|
Failed to generate code suggestions for PR |
715fdce to
239353b
Compare
|
Persistent review updated to latest commit 239353b |
|
Failed to generate code suggestions for PR |
a96a499 to
239353b
Compare
…on containing unnecessary elements for this use case
… improve bottom margin handling for the last contact
…hing folders, and searching again
239353b to
bbee23e
Compare
|
| fun searchMergedContacts(searchQuery: String, searchQueryClean: String, limit: Int = 5): List<MergedContact> { | ||
| val queryStr = if (searchQuery != searchQueryClean) { | ||
| "(name CONTAINS[c] $0 OR email CONTAINS[c] $0) OR (name CONTAINS[c] $1 OR email CONTAINS[c] $1)" | ||
| } else { | ||
| "name CONTAINS[c] $0 OR email CONTAINS[c] $0" | ||
| } | ||
| return userInfoRealm.query<MergedContact>(queryStr, searchQuery, searchQueryClean) | ||
| .sort(MergedContact::name.name) | ||
| .sort(MergedContact::comesFromApi.name, Sort.DESCENDING) | ||
| .limit(limit) | ||
| .find() | ||
| } |
There was a problem hiding this comment.
You should divide this in two function, a private "-query" one, and a public one that call the query, like this others
You should also use findSuspend instead of find
| if (!isOnlyRightShown()) { | ||
| searchViewModel.clearSearchState() | ||
| } |
There was a problem hiding this comment.
| if (!isOnlyRightShown()) { | |
| searchViewModel.clearSearchState() | |
| } | |
| if (!isOnlyRightShown()) searchViewModel.clearSearchState() |
| binding.searchBar.searchTextInput.setText(emailWithQuotes) | ||
| binding.searchBar.searchTextInput.setSelection(emailWithQuotes.length) |
There was a problem hiding this comment.
Use an apply here to avoid repeating the searchInput stuff
| val allSearchResults = combine( | ||
| contactsResults, | ||
| threadsSearchResults, | ||
| ) { contacts, threads -> |
There was a problem hiding this comment.
| val allSearchResults = combine( | |
| contactsResults, | |
| threadsSearchResults, | |
| ) { contacts, threads -> | |
| val allSearchResults = combine(contactsResults, threadsSearchResults ) { contacts, threads -> |
| var currentSearchQuery: String = "" | ||
| private set | ||
|
|
||
| val uiState = MutableLiveData<SearchUiState>(SearchUiState.IDLE) |
There was a problem hiding this comment.
This variable isn't read, so it's useless
| val contactsList = mergedContactController.searchMergedContacts(query, queryClean) | ||
| contactsList |
There was a problem hiding this comment.
Th evariable here is not very useful
|
|
||
| computeSearchFilters(folder, filters, query)?.let { newFilters -> | ||
| fetchThreads(folder, newFilters, query, shouldGetNextPage) | ||
| fetchThreads(folder, newFilters, query, shouldGetNextPage, contacts.isNotEmpty()) |
There was a problem hiding this comment.
Put the argument name for all boolean that aren't already named the same
| newFilters: Set<ThreadFilter>, | ||
| query: String, | ||
| shouldGetNextPage: Boolean, | ||
| hasContacts: Boolean = false, |
There was a problem hiding this comment.
This default value is useless as the function is only use once
Furthermore, I think we want to enforce passing an argument here to avoid forgetting that case
| threadController.saveSearchThreads(searchThreads) | ||
| } | ||
|
|
||
| enum class SearchUiState { |
There was a problem hiding this comment.
| enum class SearchUiState { | |
| private enum class SearchUiState { |
| } | ||
| } | ||
|
|
||
| fun removeBackground(){ |
There was a problem hiding this comment.
| fun removeBackground(){ | |
| fun removeBackground() { |



Expected behavior:
While the user has not pressed Enter or selected a filter, display a maximum of 5 contacts matching the search query.
When a contact is clicked, the search input is automatically populated with that contact's email address (<contact.email>).