Skip to content

Commit

Permalink
Update suggestions (IOS-190)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Nov 16, 2023
1 parent 6eadd41 commit b6f3aa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
19 changes: 15 additions & 4 deletions Mastodon/Coordinator/SceneCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,29 @@ private extension SceneCoordinator {
//MARK: - Loading

public extension SceneCoordinator {

@MainActor
func showLoading() {
guard let rootViewController else { return }
showLoading(on: rootViewController)
}

@MainActor
func showLoading(on viewController: UIViewController?) {
guard let viewController else { return }

MBProgressHUD.showAdded(to: rootViewController.view, animated: true)
MBProgressHUD.showAdded(to: viewController.view, animated: true)
}

@MainActor
func hideLoading() {
guard let rootViewController else { return }
hideLoading(on: rootViewController)
}

@MainActor
func hideLoading(on viewController: UIViewController?) {
guard let viewController else { return }

MBProgressHUD.hide(for: rootViewController.view, animated: true)
MBProgressHUD.hide(for: viewController.view, animated: true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class SuggestionAccountViewController: UIViewController, NeedsDependency {
setupNavigationBarAppearance()
defer { setupNavigationBarBackgroundView() }


title = L10n.Scene.SuggestionAccount.title
navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: UIBarButtonItem.SystemItem.done,
Expand Down Expand Up @@ -72,6 +71,8 @@ class SuggestionAccountViewController: UIViewController, NeedsDependency {
navigationItem.largeTitleDisplayMode = .automatic

tableView.deselectRow(with: transitionCoordinator, animated: animated)

viewModel.updateSuggestions()
}

//MARK: - Actions
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ final class SuggestionAccountViewModel: NSObject {

super.init()

// fetch recommended users
updateSuggestions()
}


func updateSuggestions() {
Task {
var suggestedAccounts: [Mastodon.Entity.V2.SuggestionAccount] = []
do {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b6f3aa5

Please sign in to comment.