2
2
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:
Gokul 2025-01-15 01:03:48 +05:30 committed by GitHub
parent 6ec1d9a591
commit f9ad9a4931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 1 deletions

View File

@ -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()
}
}

View File

@ -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)) ?? []

View File

@ -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 {