IceCubesApp/Packages/Lists/Sources/Lists/Edit/ListEditViewModel.swift
Thomas Ricouard 4189a59cf6
iOS 17+ only support + migrating to Observation framework (#1571)
* Initial iOS 17 + Observable migration

* More Observation

* More observation

* Checkpoint

* Checkpoint

* Bump version to 1.8.0

* SwiftFormat

* Fix home timeline switch on login

* Fix sidebar routerPath

* Fixes on detail view

* Remove print changes

* Simply detail view

* More opt

* Migrate DisplaySettingsLocalValues

* Better post detail transition

* Status detail animation finally right

* Cleanup
2023-09-18 07:01:23 +02:00

41 lines
913 B
Swift

import Combine
import Models
import Network
import Observation
import SwiftUI
@MainActor
@Observable public class ListEditViewModel {
let list: Models.List
var client: Client?
var isLoadingAccounts: Bool = true
var accounts: [Account] = []
init(list: Models.List) {
self.list = list
}
func fetchAccounts() async {
guard let client else { return }
isLoadingAccounts = true
do {
accounts = try await client.get(endpoint: Lists.accounts(listId: list.id))
isLoadingAccounts = false
} catch {
isLoadingAccounts = false
}
}
func delete(account: Account) async {
guard let client else { return }
do {
let response = try await client.delete(endpoint: Lists.updateAccounts(listId: list.id, accounts: [account.id]))
if response?.statusCode == 200 {
accounts.removeAll(where: { $0.id == account.id })
}
} catch {}
}
}