Fix user not loading on transaction details

This commit is contained in:
William Brawner 2021-10-18 06:19:44 -06:00
parent 5492322789
commit 1d6693d0cc

View file

@ -10,21 +10,18 @@ import Foundation
import Combine
class UserDataStore: ObservableObject {
var user: Result<User, NetworkError> = .failure(.loading) {
didSet {
self.objectWillChange.send()
}
}
private var currentRequest: AnyCancellable? = nil
@Published var user: Result<User, NetworkError> = .failure(.loading)
func getUser(_ id: String) {
self.user = .failure(.loading)
_ = userRepository.getUser(id)
self.currentRequest = userRepository.getUser(id)
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { (status) in
switch status {
case .finished:
self.currentRequest = nil
return
case .failure(let error):
self.user = .failure(error)
@ -36,11 +33,9 @@ class UserDataStore: ObservableObject {
}
private let userRepository: UserRepository
init(_ userRepository: UserRepository) {
self.userRepository = userRepository
}
// Needed since the default implementation is currently broken
let objectWillChange = ObservableObjectPublisher()
private let userRepository: UserRepository
}