mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-26 15:02:39 +01:00
Fix account switcher
This commit is contained in:
parent
9f894858ae
commit
64bee206b9
@ -16,9 +16,6 @@ public class AppAccountViewModel: ObservableObject {
|
|||||||
didSet {
|
didSet {
|
||||||
if let account {
|
if let account {
|
||||||
refreshAcct(account: account)
|
refreshAcct(account: account)
|
||||||
Task {
|
|
||||||
await refreshAvatar(account: account)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +41,12 @@ public class AppAccountViewModel: ObservableObject {
|
|||||||
roundedAvatar = Self.avatarsCache[appAccount.id]
|
roundedAvatar = Self.avatarsCache[appAccount.id]
|
||||||
|
|
||||||
account = try await client.get(endpoint: Accounts.verifyCredentials)
|
account = try await client.get(endpoint: Accounts.verifyCredentials)
|
||||||
|
|
||||||
Self.accountsCache[appAccount.id] = account
|
Self.accountsCache[appAccount.id] = account
|
||||||
|
|
||||||
|
if let account {
|
||||||
|
await refreshAvatar(account: account)
|
||||||
|
}
|
||||||
|
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +60,7 @@ public class AppAccountViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func refreshAvatar(account: Account) async {
|
private func refreshAvatar(account: Account) async {
|
||||||
if roundedAvatar == nil,
|
if let (data, _) = try? await URLSession.shared.data(from: account.avatar),
|
||||||
let (data, _) = try? await URLSession.shared.data(from: account.avatar),
|
|
||||||
let image = UIImage(data: data)?.roundedImage {
|
let image = UIImage(data: data)?.roundedImage {
|
||||||
roundedAvatar = image
|
roundedAvatar = image
|
||||||
Self.avatarsCache[account.id] = image
|
Self.avatarsCache[account.id] = image
|
||||||
|
Loading…
Reference in New Issue
Block a user