diff --git a/iMEGA/Node/Shared Items/SharedItemsTableViewCell.swift b/iMEGA/Node/Shared Items/SharedItemsTableViewCell.swift index c3e7968e32..66c7a65ca4 100644 --- a/iMEGA/Node/Shared Items/SharedItemsTableViewCell.swift +++ b/iMEGA/Node/Shared Items/SharedItemsTableViewCell.swift @@ -40,7 +40,6 @@ final class SharedItemsTableViewCell: UITableViewCell { func updateAppearance() { infoLabel.textColor = UIColor.mnz_subtitles(for: traitCollection) - backgroundColor = UIColor.mnz_tertiaryBackground(traitCollection) + backgroundColor = traitCollection.userInterfaceStyle == .dark ? Colors.General.Black._000000.color : Colors.General.White.ffffff.color } - } diff --git a/iMEGA/Node/Shared Items/SharedItemsViewController+Search.swift b/iMEGA/Node/Shared Items/SharedItemsViewController+Search.swift index bb616ef8d6..8e8d16f06c 100644 --- a/iMEGA/Node/Shared Items/SharedItemsViewController+Search.swift +++ b/iMEGA/Node/Shared Items/SharedItemsViewController+Search.swift @@ -18,18 +18,36 @@ extension SharedItemsViewController: UISearchBarDelegate { tableView?.reloadData() } - @objc func evaluateSearchResult(nodeArray: [MEGANode]?, error: Error?) { - DispatchQueue.main.async { - if let error { - SVProgressHUD.showError(withStatus: error.localizedDescription) - } else if let nodeArray { - if let mutableNodeArray = (nodeArray as NSArray).mutableCopy() as? NSMutableArray { - self.searchNodesArray = mutableNodeArray + func evaluateSearchResult(searchText: String, sortType: MEGASortOrderType, asyncSearchClosure: @escaping (String, MEGASortOrderType) async throws -> [MEGANode]?) async { + do { + SVProgressHUD.show() + if let nodes = try await asyncSearchClosure(searchText, sortType) { + if let mutableNodeArray = (nodes as NSArray).mutableCopy() as? NSMutableArray { + searchNodesArray = mutableNodeArray } - } else { - self.searchNodesArray.removeAllObjects() + } else { + searchNodesArray.removeAllObjects() + } + await SVProgressHUD.dismiss() + } catch { + SVProgressHUD.showError(withStatus: error.localizedDescription) + } + self.tableView?.reloadData() + } + + @objc func search(by searchText: String) { + guard let searchNodeUseCaseOCWrapper else { return } + Task { @MainActor in + if incomingButton?.isSelected ?? false { + searchUnverifiedNodes(key: searchText) + await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnInShares) + } else if outgoingButton?.isSelected ?? false { + searchUnverifiedNodes(key: searchText) + await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnOutShares) + } else if linksButton?.isSelected ?? false { + searchUnverifiedNodesArray.removeAllObjects() + await evaluateSearchResult(searchText: searchText, sortType: sortOrderType, asyncSearchClosure: searchNodeUseCaseOCWrapper.searchOnPublicLinks) } - self.tableView?.reloadData() } } diff --git a/iMEGA/Node/Shared Items/SharedItemsViewController.m b/iMEGA/Node/Shared Items/SharedItemsViewController.m index 2ae13a3596..98d368f8c6 100644 --- a/iMEGA/Node/Shared Items/SharedItemsViewController.m +++ b/iMEGA/Node/Shared Items/SharedItemsViewController.m @@ -1106,32 +1106,17 @@ - (void)tableView:(UITableView *)tableView willPerformPreviewActionForMenuWithCo - (void)updateSearchResultsForSearchController:(UISearchController *)searchController { NSString *searchString = searchController.searchBar.text; if (searchController.isActive) { - if ([searchString isEqualToString:@""]) { + if (self.searchController.searchBar.text.length < kMinimumLettersToStartTheSearch) { + if (self.searchNodeUseCaseOCWrapper != nil) { + [self.searchNodeUseCaseOCWrapper cancelSearch]; + } [self loadDefaultSharedItems]; } else { if (self.searchNodeUseCaseOCWrapper == nil) { self.searchNodeUseCaseOCWrapper = SearchNodeUseCaseOCWrapper.alloc.init; } - if (self.incomingButton.selected) { - [self searchUnverifiedNodesWithKey:searchString]; - __weak __typeof__(self) weakSelf = self; - [self.searchNodeUseCaseOCWrapper searchOnInSharesWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray * _Nullable nodes, NSError * _Nullable error) { - [weakSelf evaluateSearchResultWithNodeArray:nodes error:error]; - }]; - } else if (self.outgoingButton.selected) { - [self searchUnverifiedNodesWithKey:searchString]; - __weak __typeof__(self) weakSelf = self; - [self.searchNodeUseCaseOCWrapper searchOnOutSharesWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray * _Nullable nodes, NSError * _Nullable error) { - [weakSelf evaluateSearchResultWithNodeArray:nodes error:error]; - }]; - } else if (self.linksButton.selected) { - [self.searchUnverifiedNodesArray removeAllObjects]; - __weak __typeof__(self) weakSelf = self; - [self.searchNodeUseCaseOCWrapper searchOnPublicLinksWithText:searchString sortType:self.sortOrderType completionHandler:^(NSArray * _Nullable nodes, NSError * _Nullable error) { - [weakSelf evaluateSearchResultWithNodeArray:nodes error:error]; - }]; - } + [self searchBy:searchString]; } } else { if (self.searchNodeUseCaseOCWrapper != nil) { diff --git a/iMEGA/Utils/SharedItems/SharedItemsUseCaseOCWrapper.swift b/iMEGA/Utils/SharedItems/SharedItemsUseCaseOCWrapper.swift index 72ee5ce0d4..317a0947d6 100644 --- a/iMEGA/Utils/SharedItems/SharedItemsUseCaseOCWrapper.swift +++ b/iMEGA/Utils/SharedItems/SharedItemsUseCaseOCWrapper.swift @@ -16,7 +16,8 @@ import MEGADomain } @objc func cancelSearch() { - searchUC.cancelSearch() + searchUC.cancelSearch() + SVProgressHUD.dismiss() } private func search(type: SearchNodeTypeEntity, text: String, sortType: MEGASortOrderType) async throws -> [MEGANode]? {