84 lines
2.2 KiB
Swift
84 lines
2.2 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@ObservedObject var viewModel: ImportFlowViewModel
|
|
@State private var showingFileImporter = false
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
segmentSection
|
|
sourceSection
|
|
importSection
|
|
}
|
|
.navigationTitle(String(localized: "screen.title.import"))
|
|
.fileImporter(
|
|
isPresented: $showingFileImporter,
|
|
allowedContentTypes: viewModel.supportedContentTypes,
|
|
allowsMultipleSelection: false
|
|
) { result in
|
|
switch result {
|
|
case let .success(urls):
|
|
if let url = urls.first {
|
|
viewModel.loadFile(from: url)
|
|
}
|
|
case let .failure(error):
|
|
viewModel.errorMessage = error.localizedDescription
|
|
}
|
|
}
|
|
.alert(String(localized: "error.title"), isPresented: Binding(
|
|
get: { viewModel.errorMessage != nil },
|
|
set: { isVisible in
|
|
if !isVisible {
|
|
viewModel.errorMessage = nil
|
|
}
|
|
}
|
|
), actions: {
|
|
Button(String(localized: "button.ok"), role: .cancel) {}
|
|
}, message: {
|
|
Text(viewModel.errorMessage ?? "")
|
|
})
|
|
}
|
|
}
|
|
|
|
private var segmentSection: some View {
|
|
Section(String(localized: "section.template")) {
|
|
LabeledContent(String(localized: "label.health_segment"), value: viewModel.template.localizedHealthTypeName)
|
|
NavigationLink(String(localized: "button.configure_fields")) {
|
|
FieldMappingListView(viewModel: viewModel)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var sourceSection: some View {
|
|
Section(String(localized: "section.source")) {
|
|
Button(String(localized: "button.load_json")) {
|
|
showingFileImporter = true
|
|
}
|
|
Button(String(localized: "button.load_sample")) {
|
|
viewModel.loadBundledSample()
|
|
}
|
|
Text(String.localizedStringWithFormat(
|
|
NSLocalizedString("label.records_loaded", comment: ""),
|
|
viewModel.entries.count
|
|
))
|
|
if !viewModel.statusMessage.isEmpty {
|
|
Text(viewModel.statusMessage)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var importSection: some View {
|
|
Section(String(localized: "section.commit")) {
|
|
NavigationLink(String(localized: "button.open_import_plan")) {
|
|
ImportPlanView(viewModel: viewModel)
|
|
}
|
|
Text(String(localized: "text.commit_notice"))
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|