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