fix: homeTimeline refresh after follow people

This commit is contained in:
sunxiaojian 2021-04-21 18:52:09 +08:00
parent 9402dab97f
commit 106a5cc71a
3 changed files with 16 additions and 1 deletions

View File

@ -200,6 +200,10 @@ extension HomeTimelineViewController {
// needs trigger manually after onboarding dismiss // needs trigger manually after onboarding dismiss
setNeedsStatusBarAppearanceUpdate() setNeedsStatusBarAppearanceUpdate()
if (viewModel.fetchedResultsController.fetchedObjects ?? []).isEmpty {
viewModel.loadLatestStateMachine.enter(HomeTimelineViewModel.LoadLatestState.Loading.self)
}
} }
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
@ -280,6 +284,7 @@ extension HomeTimelineViewController {
@objc private func findPeopleButtonPressed(_ sender: PrimaryActionButton) { @objc private func findPeopleButtonPressed(_ sender: PrimaryActionButton) {
let viewModel = SuggestionAccountViewModel(context: context) let viewModel = SuggestionAccountViewModel(context: context)
viewModel.delegate = self.viewModel
coordinator.present(scene: .suggestionAccount(viewModel: viewModel), from: self, transition: .modal(animated: true, completion: nil)) coordinator.present(scene: .suggestionAccount(viewModel: viewModel), from: self, transition: .modal(animated: true, completion: nil))
} }

View File

@ -129,3 +129,9 @@ final class HomeTimelineViewModel: NSObject {
} }
} }
extension HomeTimelineViewModel: SuggestionAccountViewModelDelegate {
func homeTimelineNeedRefresh() {
loadLatestStateMachine.enter(LoadLatestState.Loading.self)
}
}

View File

@ -13,12 +13,16 @@ import MastodonSDK
import os.log import os.log
import UIKit import UIKit
protocol SuggestionAccountViewModelDelegate: AnyObject {
func homeTimelineNeedRefresh()
}
final class SuggestionAccountViewModel: NSObject { final class SuggestionAccountViewModel: NSObject {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
// input // input
let context: AppContext let context: AppContext
weak var delegate: SuggestionAccountViewModelDelegate?
// output // output
let accounts = CurrentValueSubject<[NSManagedObjectID], Never>([]) let accounts = CurrentValueSubject<[NSManagedObjectID], Never>([])
var selectedAccounts = [NSManagedObjectID]() var selectedAccounts = [NSManagedObjectID]()
@ -137,7 +141,7 @@ final class SuggestionAccountViewModel: NSObject {
case .failure(let error): case .failure(let error):
os_log("%{public}s[%{public}ld], %{public}s: follow failed. %s", (#file as NSString).lastPathComponent, #line, #function, error.localizedDescription) os_log("%{public}s[%{public}ld], %{public}s: follow failed. %s", (#file as NSString).lastPathComponent, #line, #function, error.localizedDescription)
case .finished: case .finished:
// handle isFetchingLatestTimeline in fetch controller delegate self.delegate?.homeTimelineNeedRefresh()
break break
} }
} receiveValue: { _ in } receiveValue: { _ in