Impressia/Vernissage/Widgets/SettingsView/AccountsSection.swift

52 lines
1.7 KiB
Swift
Raw Normal View History

2023-01-13 13:37:01 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
struct AccountsSection: View {
2023-01-27 17:31:28 +01:00
@EnvironmentObject var applicationState: ApplicationState
2023-01-13 13:37:01 +01:00
@State private var accounts: [AccountData] = []
var body: some View {
Section("Accounts") {
ForEach(self.accounts) { account in
2023-01-27 17:31:28 +01:00
HStack(alignment: .center) {
UsernameRow(accountId: account.id,
accountAvatar: account.avatar,
accountDisplayName: account.displayName,
accountUsername: account.username)
Spacer()
if self.applicationState.accountData?.id == account.id {
Image(systemName: "checkmark")
.foregroundColor(self.applicationState.tintColor.color())
}
}
.deleteDisabled(self.applicationState.accountData?.id == account.id)
2023-01-13 13:37:01 +01:00
}
2023-01-27 17:31:28 +01:00
.onDelete(perform: delete)
2023-01-13 13:37:01 +01:00
2023-01-23 18:01:27 +01:00
NavigationLink(value: RouteurDestinations.signIn) {
2023-01-13 13:37:01 +01:00
HStack {
Text("New account")
Spacer()
Image(systemName: "person.crop.circle.badge.plus")
}
}
}
.task {
self.accounts = AccountDataHandler.shared.getAccountsData()
}
}
2023-01-27 17:31:28 +01:00
func delete(at offsets: IndexSet) {
let accountsToDelete = offsets.map { self.accounts[$0] }
for account in accountsToDelete {
AccountDataHandler.shared.remove(accountData: account)
}
}
2023-01-13 13:37:01 +01:00
}