Combine all account sync changes into a single batch update to prevent the sidebar from jumping around

This commit is contained in:
Maurice Parker 2020-10-31 12:52:15 -05:00
parent 1760d38777
commit 295bca326a
1 changed files with 14 additions and 20 deletions

View File

@ -561,11 +561,21 @@ private extension ReaderAPIAccountDelegate {
caller.retrieveTags { result in caller.retrieveTags { result in
switch result { switch result {
case .success(let tags): case .success(let tags):
BatchUpdate.shared.perform {
self.syncFolders(account, tags)
}
self.refreshProgress.completeTask() self.refreshProgress.completeTask()
self.refreshFeeds(account, completion: completion) self.caller.retrieveSubscriptions { result in
self.refreshProgress.completeTask()
switch result {
case .success(let subscriptions):
BatchUpdate.shared.perform {
self.syncFolders(account, tags)
self.syncFeeds(account, subscriptions)
self.syncFeedFolderRelationship(account, subscriptions)
}
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
case .failure(let error): case .failure(let error):
completion(.failure(error)) completion(.failure(error))
} }
@ -614,22 +624,6 @@ private extension ReaderAPIAccountDelegate {
} }
func refreshFeeds(_ account: Account, completion: @escaping (Result<Void, Error>) -> Void) {
caller.retrieveSubscriptions { result in
switch result {
case .success(let subscriptions):
self.refreshProgress.completeTask()
BatchUpdate.shared.perform {
self.syncFeeds(account, subscriptions)
self.syncFeedFolderRelationship(account, subscriptions)
}
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
}
func syncFeeds(_ account: Account, _ subscriptions: [ReaderAPISubscription]?) { func syncFeeds(_ account: Account, _ subscriptions: [ReaderAPISubscription]?) {
guard let subscriptions = subscriptions else { return } guard let subscriptions = subscriptions else { return }