diff --git a/Vernissage/CoreData/AccountDataHandler.swift b/Vernissage/CoreData/AccountDataHandler.swift index e68b297..6bc8bc2 100644 --- a/Vernissage/CoreData/AccountDataHandler.swift +++ b/Vernissage/CoreData/AccountDataHandler.swift @@ -52,6 +52,17 @@ class AccountDataHandler { } } + func remove(accountData: AccountData) { + let context = CoreDataHandler.shared.container.viewContext + context.delete(accountData) + + do { + try context.save() + } catch { + ErrorService.shared.handle(error, message: "Error during deleting account data (remove).") + } + } + func createAccountDataEntity() -> AccountData { let context = CoreDataHandler.shared.container.viewContext return AccountData(context: context) diff --git a/Vernissage/Widgets/ImagesCarousel.swift b/Vernissage/Widgets/ImagesCarousel.swift index 57817da..af55fac 100644 --- a/Vernissage/Widgets/ImagesCarousel.swift +++ b/Vernissage/Widgets/ImagesCarousel.swift @@ -57,10 +57,6 @@ struct ImagesCarousel: View { self.imageHeight = UIScreen.main.bounds.width * 0.75 self.heightWasPrecalculated = false } - - print(self.heightWasPrecalculated) - print(self.imageWidth) - print(self.imageHeight) } var body: some View { diff --git a/Vernissage/Widgets/SettingsView/AccountsSection.swift b/Vernissage/Widgets/SettingsView/AccountsSection.swift index 7627183..9bfa4a3 100644 --- a/Vernissage/Widgets/SettingsView/AccountsSection.swift +++ b/Vernissage/Widgets/SettingsView/AccountsSection.swift @@ -7,16 +7,27 @@ import SwiftUI struct AccountsSection: View { + @EnvironmentObject var applicationState: ApplicationState + @State private var accounts: [AccountData] = [] var body: some View { Section("Accounts") { ForEach(self.accounts) { account in - UsernameRow(accountId: account.id, - accountAvatar: account.avatar, - accountDisplayName: account.displayName, - accountUsername: account.username) + 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) } + .onDelete(perform: delete) NavigationLink(value: RouteurDestinations.signIn) { HStack { @@ -30,4 +41,11 @@ struct AccountsSection: View { self.accounts = AccountDataHandler.shared.getAccountsData() } } + + func delete(at offsets: IndexSet) { + let accountsToDelete = offsets.map { self.accounts[$0] } + for account in accountsToDelete { + AccountDataHandler.shared.remove(accountData: account) + } + } } diff --git a/Vernissage/Widgets/SettingsView/AvatarShapesSection.swift b/Vernissage/Widgets/SettingsView/AvatarShapesSection.swift index 70770a5..29cb32f 100644 --- a/Vernissage/Widgets/SettingsView/AvatarShapesSection.swift +++ b/Vernissage/Widgets/SettingsView/AvatarShapesSection.swift @@ -32,6 +32,7 @@ struct AvatarShapesSection: View { } } } + .padding(.vertical, 4) Button { self.applicationState.avatarShape = .roundedRectangle @@ -53,6 +54,7 @@ struct AvatarShapesSection: View { } } } + .padding(.vertical, 4) } } }