Fix user not loading on transaction details
This commit is contained in:
parent
5492322789
commit
1d6693d0cc
1 changed files with 6 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue