forked from zelo72/mastodon-ios
feat: add reload to Hashtags tab for Discovery scene
This commit is contained in:
parent
9477071556
commit
c3bd5528fa
|
@ -31,6 +31,8 @@ final class DiscoveryHashtagsViewController: UIViewController, NeedsDependency,
|
|||
return tableView
|
||||
}()
|
||||
|
||||
let refreshControl = UIRefreshControl()
|
||||
|
||||
deinit {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
}
|
||||
|
@ -60,6 +62,9 @@ extension DiscoveryHashtagsViewController {
|
|||
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
tableView.refreshControl = refreshControl
|
||||
refreshControl.addTarget(self, action: #selector(DiscoveryHashtagsViewController.refreshControlValueChanged(_:)), for: .valueChanged)
|
||||
|
||||
tableView.delegate = self
|
||||
viewModel.setupDiffableDataSource(
|
||||
tableView: tableView
|
||||
|
@ -80,6 +85,21 @@ extension DiscoveryHashtagsViewController {
|
|||
|
||||
}
|
||||
|
||||
extension DiscoveryHashtagsViewController {
|
||||
|
||||
@objc private func refreshControlValueChanged(_ sender: UIRefreshControl) {
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try await viewModel.fetch()
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
sender.endRefreshing()
|
||||
} // end Task
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDelegate
|
||||
extension DiscoveryHashtagsViewController: UITableViewDelegate {
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import MastodonSDK
|
|||
|
||||
final class DiscoveryHashtagsViewModel {
|
||||
|
||||
let logger = Logger(subsystem: "DiscoveryHashtagsViewModel", category: "ViewModel")
|
||||
|
||||
var disposeBag = Set<AnyCancellable>()
|
||||
|
||||
// input
|
||||
|
@ -61,3 +63,14 @@ final class DiscoveryHashtagsViewModel {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
extension DiscoveryHashtagsViewModel {
|
||||
|
||||
@MainActor
|
||||
func fetch() async throws {
|
||||
guard let authenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||
let response = try await context.apiService.trendHashtags(domain: authenticationBox.domain, query: nil)
|
||||
hashtags = response.value.filter { !$0.name.isEmpty }
|
||||
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch tags: \(response.value.count)")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue