Account deletion.

This commit is contained in:
Marcin Czachursk 2023-01-27 17:31:28 +01:00
parent 62e1995005
commit c4f07a54a3
4 changed files with 35 additions and 8 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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)
}
}
}

View File

@ -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)
}
}
}