mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 06:49:12 +00:00
added a cancel button, extract logic
This commit is contained in:
@@ -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,30 +92,26 @@ struct ImportView: View {
|
|||||||
Toggle("Replace Events", isOn: $replaceCurrentEvents)
|
Toggle("Replace Events", isOn: $replaceCurrentEvents)
|
||||||
.foregroundStyle(.two)
|
.foregroundStyle(.two)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
HStack {
|
||||||
Button() {
|
Button() {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
showAlert.toggle()
|
showAlert.toggle()
|
||||||
}
|
}
|
||||||
do throws {
|
importEvents()
|
||||||
try viewModel.importEvents(importStr, replace: replaceCurrentEvents)
|
} label: {
|
||||||
|
Text("cancel")
|
||||||
|
.font(.title2)
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
|
.buttonStyle(BorderedProminentButtonStyle())
|
||||||
|
|
||||||
|
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: {
|
} label: {
|
||||||
Text("yes")
|
Text("yes")
|
||||||
.font(.title2)
|
.font(.title2)
|
||||||
@@ -102,6 +121,8 @@ struct ImportView: View {
|
|||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
.frame(maxWidth: 250, maxHeight: 250)
|
.frame(maxWidth: 250, maxHeight: 250)
|
||||||
}
|
}
|
||||||
.opacity(showAlert ? 1 : 0)
|
.opacity(showAlert ? 1 : 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user