From dfb1dae545d6eaddca1056c4e5624d43b9896883 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Wed, 28 May 2025 14:52:43 +0100 Subject: [PATCH] added a cancel button, extract logic --- NearFuture/Views/Settings/ImportView.swift | 71 ++++++++++++++-------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/NearFuture/Views/Settings/ImportView.swift b/NearFuture/Views/Settings/ImportView.swift index f545deb..efd9a0c 100644 --- a/NearFuture/Views/Settings/ImportView.swift +++ b/NearFuture/Views/Settings/ImportView.swift @@ -19,6 +19,29 @@ struct ImportView: View { @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 { ZStack(alignment: .center) { List { @@ -69,36 +92,34 @@ struct ImportView: View { Toggle("Replace Events", isOn: $replaceCurrentEvents) .foregroundStyle(.two) Spacer() - Button() { - withAnimation { - showAlert.toggle() + HStack { + Button() { + withAnimation { + showAlert.toggle() + } + importEvents() + } label: { + Text("cancel") + .font(.title2) + .bold() } - do throws { - try viewModel.importEvents(importStr, replace: replaceCurrentEvents) + .buttonStyle(BorderedProminentButtonStyle()) + + Spacer() + + Button() { 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 + showAlert.toggle() } + importEvents() + } label: { + Text("yes") + .font(.title2) + .bold() } - } label: { - Text("yes") - .font(.title2) - .bold() + .buttonStyle(BorderedProminentButtonStyle()) } - .buttonStyle(BorderedProminentButtonStyle()) + .padding() } .padding() }