Don't search for unnecessary data

This commit is contained in:
Shadowfacts 2020-10-16 19:14:29 -04:00
parent 5414f2329c
commit e0acb0f04a
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 18 additions and 10 deletions

View File

@ -13,11 +13,18 @@ class AddSavedHashtagViewController: SearchResultsViewController {
var searchController: UISearchController!
init(mastodonController: MastodonController) {
super.init(mastodonController: mastodonController, resultTypes: [.hashtags])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
onlySections = [.hashtags]
searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false

View File

@ -52,9 +52,8 @@ class EditListAccountsViewController: EnhancedTableViewController {
})
dataSource.editListAccountsController = self
searchResultsController = SearchResultsViewController(mastodonController: mastodonController)
searchResultsController = SearchResultsViewController(mastodonController: mastodonController, resultTypes: [.accounts])
searchResultsController.delegate = self
searchResultsController.onlySections = [.accounts]
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchResultsUpdater = searchResultsController

View File

@ -35,15 +35,17 @@ class SearchResultsViewController: EnhancedTableViewController {
var dataSource: UITableViewDiffableDataSource<Section, Item>!
var activityIndicator: UIActivityIndicatorView!
private var activityIndicator: UIActivityIndicatorView!
var onlySections: [Section] = Section.allCases
/// Types of results to search for. `nil` means all results will be included.
var resultTypes: [SearchResultType]? = nil
let searchSubject = PassthroughSubject<String?, Never>()
var currentQuery: String?
init(mastodonController: MastodonController) {
init(mastodonController: MastodonController, resultTypes: [SearchResultType]? = nil) {
self.mastodonController = mastodonController
self.resultTypes = resultTypes
super.init(style: .grouped)
@ -128,7 +130,7 @@ class SearchResultsViewController: EnhancedTableViewController {
activityIndicator.isHidden = false
activityIndicator.startAnimating()
let request = Client.search(query: query, resolve: true, limit: 10)
let request = Client.search(query: query, types: resultTypes, resolve: true, limit: 10)
mastodonController.run(request) { (response) in
guard case let .success(results, _) = response else { fatalError() }
@ -157,16 +159,16 @@ class SearchResultsViewController: EnhancedTableViewController {
}
}
if self.onlySections.contains(.accounts) && !results.accounts.isEmpty {
if !results.accounts.isEmpty {
snapshot.appendSections([.accounts])
snapshot.appendItems(results.accounts.map { .account($0.id) }, toSection: .accounts)
addAccounts(results.accounts)
}
if self.onlySections.contains(.hashtags) && !results.hashtags.isEmpty {
if !results.hashtags.isEmpty {
snapshot.appendSections([.hashtags])
snapshot.appendItems(results.hashtags.map { .hashtag($0) }, toSection: .hashtags)
}
if self.onlySections.contains(.statuses) && !results.statuses.isEmpty {
if !results.statuses.isEmpty {
snapshot.appendSections([.statuses])
snapshot.appendItems(results.statuses.map { .status($0.id, .unknown) }, toSection: .statuses)
addStatuses(results.statuses)