diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index d74a4ccd8..ef15ce6e4 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -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) } } diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift index 0fddc36d8..84d4f9e23 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewController.swift @@ -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) } } diff --git a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift index cb83ae511..84cc4c46d 100644 --- a/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift +++ b/Mastodon/Scene/SuggestionAccount/SuggestionAccountViewModel.swift @@ -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 {