Skip to content

Commit

Permalink
Merge pull request #560 from Infomaniak/search
Browse files Browse the repository at this point in the history
Search
  • Loading branch information
Lnamw authored Feb 8, 2023
2 parents 0e0f90f + b7d444c commit fcb8291
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions Mail/Views/Search/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ struct SearchView: View {
Group {
if thread.shouldPresentAsDraft {
Button(action: {
DraftUtils.editDraft(from: thread, mailboxManager: viewModel.mailboxManager, editedMessageDraft: $editedMessageDraft)
DraftUtils.editDraft(
from: thread,
mailboxManager: viewModel.mailboxManager,
editedMessageDraft: $editedMessageDraft
)
}, label: {
ThreadCell(thread: thread,
mailboxManager: viewModel.mailboxManager,
Expand All @@ -179,6 +183,8 @@ struct SearchView: View {
}
}
}
.listRowInsets(EdgeInsets())
.padding(.leading, -4)
.onAppear {
viewModel.loadNextPageIfNeeded(currentItem: thread)
}
Expand Down Expand Up @@ -210,6 +216,7 @@ struct SearchView: View {
}
}
.padding(.horizontal, 4)
.padding(.vertical, threadDensity.cellVerticalPadding)
} header: {
if !contacts.isEmpty {
Text(MailResourcesStrings.Localizable.contactsSearch)
Expand Down Expand Up @@ -260,7 +267,10 @@ struct SearchView: View {
private func deleteSearchTapped(searchItem: String) {
Task {
await tryOrDisplayError {
viewModel.searchHistory = await viewModel.mailboxManager.delete(searchHistory: viewModel.searchHistory, with: searchItem)
viewModel.searchHistory = await viewModel.mailboxManager.delete(
searchHistory: viewModel.searchHistory,
with: searchItem
)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions Mail/Views/Search/SearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ enum SearchState {

init(mailboxManager: MailboxManager, folder: Folder?) {
self.mailboxManager = mailboxManager
self.searchHistory = mailboxManager.searchHistory()
searchHistory = mailboxManager.searchHistory()
trashFolderId = mailboxManager.getFolder(with: .trash)?._id ?? ""
realFolder = folder

Expand All @@ -97,7 +97,8 @@ enum SearchState {
searchFieldObservation = $searchValue
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main)
.sink { [weak self] newValue in
guard self?.lastSearch.trimmingCharacters(in: .whitespacesAndNewlines) != newValue.trimmingCharacters(in: .whitespacesAndNewlines) else {
guard self?.lastSearch.trimmingCharacters(in: .whitespacesAndNewlines) != newValue
.trimmingCharacters(in: .whitespacesAndNewlines) else {
return
}
self?.lastSearch = newValue
Expand Down Expand Up @@ -219,8 +220,9 @@ enum SearchState {
.contains(where: { $0.email.caseInsensitiveCompare(searchValue) == .orderedSame }) {
autocompleteRecipients.append(Recipient(email: searchValue, name: ""))
}
let contactRange: Range<Int> = 0 ..< min(autocompleteRecipients.count, Constants.contactSuggestionLimit)
withAnimation {
contacts = autocompleteRecipients
contacts = Array(autocompleteRecipients[contactRange])
}
}

Expand Down
1 change: 1 addition & 0 deletions MailCore/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public enum Constants {
}

public static let messageQuantityLimit = 500
public static let contactSuggestionLimit = 5

public static func longUid(from shortUid: String, folderId: String) -> String {
return "\(shortUid)@\(folderId)"
Expand Down

0 comments on commit fcb8291

Please sign in to comment.