added a cancel button, extract logic

This commit is contained in:
neon443
2025-05-28 14:52:43 +01:00
parent 0f3b86fe8c
commit dfb1dae545

View File

@@ -19,6 +19,29 @@ struct ImportView: View {
@State private var replaceCurrentEvents: Bool = false @State private var replaceCurrentEvents: Bool = false
fileprivate func importEvents() {
do throws {
try viewModel.importEvents(importStr, replace: replaceCurrentEvents)
withAnimation {
image = "checkmark.circle.fill"
text = "Complete"
fgColor = .green
}
} catch importError.invalidB64 {
withAnimation {
image = "xmark.app.fill"
text = "Invalid base64 input."
fgColor = .red
}
} catch {
withAnimation {
image = "xmark.app.fill"
text = error.localizedDescription
fgColor = .red
}
}
}
var body: some View { var body: some View {
ZStack(alignment: .center) { ZStack(alignment: .center) {
List { List {
@@ -69,36 +92,34 @@ struct ImportView: View {
Toggle("Replace Events", isOn: $replaceCurrentEvents) Toggle("Replace Events", isOn: $replaceCurrentEvents)
.foregroundStyle(.two) .foregroundStyle(.two)
Spacer() Spacer()
Button() { HStack {
withAnimation { Button() {
showAlert.toggle() withAnimation {
showAlert.toggle()
}
importEvents()
} label: {
Text("cancel")
.font(.title2)
.bold()
} }
do throws { .buttonStyle(BorderedProminentButtonStyle())
try viewModel.importEvents(importStr, replace: replaceCurrentEvents)
Spacer()
Button() {
withAnimation { withAnimation {
image = "checkmark.circle.fill" showAlert.toggle()
text = "Complete"
fgColor = .green
}
} catch importError.invalidB64 {
withAnimation {
image = "xmark.app.fill"
text = "Invalid base64 input."
fgColor = .red
}
} catch {
withAnimation {
image = "xmark.app.fill"
text = error.localizedDescription
fgColor = .red
} }
importEvents()
} label: {
Text("yes")
.font(.title2)
.bold()
} }
} label: { .buttonStyle(BorderedProminentButtonStyle())
Text("yes")
.font(.title2)
.bold()
} }
.buttonStyle(BorderedProminentButtonStyle()) .padding()
} }
.padding() .padding()
} }