mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-09 08:49:36 +00:00
4189a59cf6
* 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
48 lines
1.1 KiB
Swift
48 lines
1.1 KiB
Swift
import Models
|
|
import Network
|
|
import Observation
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
@Observable class ListAddAccountViewModel {
|
|
let account: Account
|
|
|
|
var inLists: [Models.List] = []
|
|
var isLoadingInfo: Bool = true
|
|
|
|
var client: Client?
|
|
|
|
init(account: Account) {
|
|
self.account = account
|
|
}
|
|
|
|
func fetchInfo() async {
|
|
guard let client else { return }
|
|
isLoadingInfo = true
|
|
do {
|
|
inLists = try await client.get(endpoint: Accounts.lists(id: account.id))
|
|
isLoadingInfo = false
|
|
} catch {
|
|
withAnimation {
|
|
isLoadingInfo = false
|
|
}
|
|
}
|
|
}
|
|
|
|
func addToList(list: Models.List) async {
|
|
guard let client else { return }
|
|
let response = try? await client.post(endpoint: Lists.updateAccounts(listId: list.id, accounts: [account.id]))
|
|
if response?.statusCode == 200 {
|
|
inLists.append(list)
|
|
}
|
|
}
|
|
|
|
func removeFromList(list: Models.List) async {
|
|
guard let client else { return }
|
|
let response = try? await client.delete(endpoint: Lists.updateAccounts(listId: list.id, accounts: [account.id]))
|
|
if response?.statusCode == 200 {
|
|
inLists.removeAll(where: { $0.id == list.id })
|
|
}
|
|
}
|
|
}
|