Account deletion.
This commit is contained in:
parent
62e1995005
commit
c4f07a54a3
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue