mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-29 05:38:06 +00:00
28 lines
580 B
Swift
28 lines
580 B
Swift
|
import SwiftUI
|
||
|
import Network
|
||
|
import Models
|
||
|
|
||
|
@MainActor
|
||
|
class AccountDetailViewModel: ObservableObject {
|
||
|
let accountId: String
|
||
|
var client: Client = .init(server: "")
|
||
|
|
||
|
enum State {
|
||
|
case loading, data(account: Models.Account), error(error: Error)
|
||
|
}
|
||
|
|
||
|
@Published var state: State = .loading
|
||
|
|
||
|
init(accountId: String) {
|
||
|
self.accountId = accountId
|
||
|
}
|
||
|
|
||
|
func fetchAccount() async {
|
||
|
do {
|
||
|
state = .data(account: try await client.fetch(endpoint: Network.Account.accounts(id: accountId)))
|
||
|
} catch {
|
||
|
state = .error(error: error)
|
||
|
}
|
||
|
}
|
||
|
}
|