mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 22:56:15 +00:00
Fix import/Export events
rewrote the daysTillEventt()
This commit is contained in:
61
NearFuture/ImportView.swift
Normal file
61
NearFuture/ImportView.swift
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// ImportView.swift
|
||||
// NearFuture
|
||||
//
|
||||
// Created by neon443 on 02/05/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ImportView: View {
|
||||
@ObservedObject var viewModel: EventViewModel
|
||||
@Binding var importStr: String
|
||||
|
||||
@State private var image: String = "clock.fill"
|
||||
@State private var text: String = "Ready..."
|
||||
@State private var fgColor: Color = .yellow
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section("Status") {
|
||||
Label(text, systemImage: image)
|
||||
.contentTransition(.numericText())
|
||||
.foregroundStyle(fgColor)
|
||||
}
|
||||
TextField("", text: $importStr)
|
||||
Button() {
|
||||
do throws {
|
||||
try viewModel.importEvents(importStr)
|
||||
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
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label("Import", systemImage: "tray.and.arrow.down.fill")
|
||||
}
|
||||
.disabled(importStr.isEmpty)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ImportView(
|
||||
viewModel: dummyEventViewModel(),
|
||||
importStr: .constant("kljadfskljafdlkj;==")
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user