mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
If recent search history is empty show text like No recent searches (#1387)
Displayed no recent searches text if recent search is empty
This commit is contained in:
parent
6ec1d9a591
commit
f9ad9a4931
@ -10,6 +10,8 @@ import Combine
|
||||
import CoreDataStack
|
||||
import MastodonCore
|
||||
import MastodonUI
|
||||
import MastodonLocalization
|
||||
import MastodonAsset
|
||||
|
||||
final class SearchHistoryViewController: UIViewController {
|
||||
|
||||
@ -27,6 +29,14 @@ final class SearchHistoryViewController: UIViewController {
|
||||
collectionView.keyboardDismissMode = .onDrag
|
||||
return collectionView
|
||||
}()
|
||||
|
||||
private let noSearchResultLabel: UILabel = {
|
||||
let label: UILabel = UILabel()
|
||||
label.text = L10n.Scene.Search.Searching.noSearchResults
|
||||
label.textColor = .secondaryLabel
|
||||
label.isHidden = true // Initially Hiden
|
||||
return label
|
||||
}()
|
||||
}
|
||||
|
||||
extension SearchHistoryViewController {
|
||||
@ -38,7 +48,8 @@ extension SearchHistoryViewController {
|
||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(collectionView)
|
||||
collectionView.pinToParent()
|
||||
|
||||
self.setupNoSearchResultLabel()
|
||||
updateNoRecentSearchLabelUI()
|
||||
collectionView.delegate = self
|
||||
viewModel.setupDiffableDataSource(
|
||||
collectionView: collectionView,
|
||||
@ -49,6 +60,22 @@ extension SearchHistoryViewController {
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
viewModel.items = (try? FileManager.default.searchItems(for: authenticationBox)) ?? []
|
||||
}
|
||||
|
||||
private func setupNoSearchResultLabel() {
|
||||
noSearchResultLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(noSearchResultLabel)
|
||||
NSLayoutConstraint.activate([
|
||||
noSearchResultLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
noSearchResultLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
private func updateNoRecentSearchLabelUI() {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.noSearchResultLabel.isHidden = !self.viewModel.isRecentSearchEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UICollectionViewDelegate
|
||||
@ -101,6 +128,7 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
|
||||
) {
|
||||
FileManager.default.removeSearchHistory(for: authenticationBox)
|
||||
viewModel.items = []
|
||||
self.updateNoRecentSearchLabelUI()
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,5 +136,6 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
|
||||
extension SearchHistoryViewController: SearchResultOverviewCoordinatorDelegate {
|
||||
func newSearchHistoryItemAdded(_ coordinator: SearchResultOverviewCoordinator) {
|
||||
viewModel.items = (try? FileManager.default.searchItems(for: authenticationBox)) ?? []
|
||||
self.updateNoRecentSearchLabelUI()
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ final class SearchHistoryViewModel {
|
||||
// output
|
||||
var diffableDataSource: UICollectionViewDiffableDataSource<SearchHistorySection, SearchHistoryItem>?
|
||||
|
||||
public var isRecentSearchEmpty: Bool {
|
||||
return items.isEmpty
|
||||
}
|
||||
|
||||
init(authenticationBox: MastodonAuthenticationBox) {
|
||||
self.authenticationBox = authenticationBox
|
||||
self.items = (try? FileManager.default.searchItems(for: authenticationBox)) ?? []
|
||||
|
@ -1464,6 +1464,8 @@ public enum L10n {
|
||||
}
|
||||
/// Recent searches
|
||||
public static let recentSearch = L10n.tr("Localizable", "Scene.Search.Searching.RecentSearch", fallback: "Recent searches")
|
||||
/// No search results
|
||||
public static let noSearchResults = L10n.tr("Localizable", "Scene.Search.Searching.NoSearchResults", fallback: "No recent searches.")
|
||||
/// Open URL in Mastodon
|
||||
public static let url = L10n.tr("Localizable", "Scene.Search.Searching.Url", fallback: "Open URL in Mastodon")
|
||||
public enum EmptyState {
|
||||
|
Loading…
x
Reference in New Issue
Block a user