Update suggestions (IOS-190)

This commit is contained in:
Nathan Mattes 2023-11-13 15:48:45 +01:00
parent 6eadd41c43
commit b6f3aa52de
3 changed files with 26 additions and 8 deletions

View File

@ -562,18 +562,29 @@ private extension SceneCoordinator {
//MARK: - Loading
public extension SceneCoordinator {
@MainActor
func showLoading() {
guard let rootViewController else { return }
showLoading(on: rootViewController)
}
MBProgressHUD.showAdded(to: rootViewController.view, animated: true)
@MainActor
func showLoading(on viewController: UIViewController?) {
guard let viewController else { return }
MBProgressHUD.showAdded(to: viewController.view, animated: true)
}
@MainActor
func hideLoading() {
guard let rootViewController else { return }
hideLoading(on: rootViewController)
}
MBProgressHUD.hide(for: rootViewController.view, animated: true)
@MainActor
func hideLoading(on viewController: UIViewController?) {
guard let viewController else { return }
MBProgressHUD.hide(for: viewController.view, animated: true)
}
}

View File

@ -38,7 +38,6 @@ class SuggestionAccountViewController: UIViewController, NeedsDependency {
setupNavigationBarAppearance()
defer { setupNavigationBarBackgroundView() }
title = L10n.Scene.SuggestionAccount.title
navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: UIBarButtonItem.SystemItem.done,
@ -72,6 +71,8 @@ class SuggestionAccountViewController: UIViewController, NeedsDependency {
navigationItem.largeTitleDisplayMode = .automatic
tableView.deselectRow(with: transitionCoordinator, animated: animated)
viewModel.updateSuggestions()
}
//MARK: - Actions
@ -122,8 +123,9 @@ extension SuggestionAccountViewController: SuggestionAccountTableViewCellDelegat
extension SuggestionAccountViewController: SuggestionAccountTableViewFooterDelegate {
func followAll(_ footerView: SuggestionAccountTableViewFooter) {
viewModel.followAllSuggestedAccounts(self) {
viewModel.followAllSuggestedAccounts(self, presentedOn: self.navigationController) {
DispatchQueue.main.async {
self.coordinator.hideLoading(on: self.navigationController)
self.dismiss(animated: true)
}
}

View File

@ -42,7 +42,11 @@ final class SuggestionAccountViewModel: NSObject {
super.init()
// fetch recommended users
updateSuggestions()
}
func updateSuggestions() {
Task {
var suggestedAccounts: [Mastodon.Entity.V2.SuggestionAccount] = []
do {
@ -106,11 +110,12 @@ final class SuggestionAccountViewModel: NSObject {
.store(in: &disposeBag)
}
func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider, completion: (() -> Void)? = nil) {
func followAllSuggestedAccounts(_ dependency: NeedsDependency & AuthContextProvider, presentedOn: UIViewController?, completion: (() -> Void)? = nil) {
let tmpAccounts = accounts.compactMap { $0.account }
Task {
await dependency.coordinator.showLoading(on: presentedOn)
await withTaskGroup(of: Void.self, body: { taskGroup in
for account in tmpAccounts {
taskGroup.addTask {