diff --git a/PAWS/ECGRecordings/ECGModule.swift b/PAWS/ECGRecordings/ECGModule.swift index 3186ca2a..10166cd9 100644 --- a/PAWS/ECGRecordings/ECGModule.swift +++ b/PAWS/ECGRecordings/ECGModule.swift @@ -19,6 +19,7 @@ class ECGModule: Module, DefaultInitializable, EnvironmentAccessible { @ObservationIgnored @Dependency var localStorage: LocalStorage + @ObservationIgnored @StandardActor var standard: PAWSStandard private(set) var electrocardiograms: [HKElectrocardiogram] = [] private var uploadedElectrocardiograms: Set = [] @@ -33,8 +34,16 @@ class ECGModule: Module, DefaultInitializable, EnvironmentAccessible { } - func isUploaded(_ electrocardiogram: HKElectrocardiogram) -> Bool { - uploadedElectrocardiograms.contains(where: { $0 == electrocardiogram.uuid }) + func isUploaded(_ electrocardiogram: HKElectrocardiogram, reuploadIfNeeded: Bool = false) -> Bool { + let uploaded = uploadedElectrocardiograms.contains(where: { $0 == electrocardiogram.uuid }) + + if reuploadIfNeeded { + Task { + await standard.add(sample: electrocardiogram) + } + } + + return uploaded } func markAsUploaded(_ electrocardiogram: HKElectrocardiogram) { diff --git a/PAWS/ECGRecordings/ECGRecording.swift b/PAWS/ECGRecordings/ECGRecording.swift index def82e12..b4039811 100644 --- a/PAWS/ECGRecordings/ECGRecording.swift +++ b/PAWS/ECGRecordings/ECGRecording.swift @@ -13,16 +13,30 @@ import SwiftUI struct ECGRecording: View { let electrocardiogram: HKElectrocardiogram @State var symptoms: HKElectrocardiogram.Symptoms = [:] + @Environment(ECGModule.self) var ecgModule var body: some View { PAWSCard { VStack(alignment: .leading) { - Text("ECG Recording") - .font(.title) - Text(electrocardiogram.endDate.formatted()) - .font(.subheadline) - .foregroundStyle(.secondary) + VStack(alignment: .leading, spacing: 0) { + Text("ECG Recording") + .font(.title) + HStack { + Text(electrocardiogram.endDate.formatted()) + .font(.subheadline) + .foregroundStyle(.secondary) + if ecgModule.isUploaded(electrocardiogram, reuploadIfNeeded: true) { + Image(systemName: "checkmark.circle.fill") + .foregroundStyle(.green) + .accessibilityLabel("Checkmark: ECG has been successfully uploaded") + } else { + ProgressView() + .controlSize(.small) + .padding(.horizontal, 1) + } + } + } Divider() if symptoms.isEmpty { Text("Recorded no symptoms") diff --git a/PAWS/PAWSStandard.swift b/PAWS/PAWSStandard.swift index a8fd3da3..d3899e87 100644 --- a/PAWS/PAWSStandard.swift +++ b/PAWS/PAWSStandard.swift @@ -147,13 +147,9 @@ actor PAWSStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onboar let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes] let jsonRepresentation = (try? String(data: encoder.encode(resource), encoding: .utf8)) ?? "" - try? await mockWebService.upload(path: "healthkit/\(sample.uuid.uuidString)", body: jsonRepresentation) + try await mockWebService.upload(path: "healthkit/\(sample.uuid.uuidString)", body: jsonRepresentation) } else { - do { - try await healthKitDocument(id: sample.id).setData(from: resource) - } catch { - logger.error("Could not store HealthKit sample: \(error)") - } + try await healthKitDocument(id: sample.id).setData(from: resource) } if let electrocardiogram = sample as? HKElectrocardiogram { diff --git a/PAWS/Resources/Localizable.xcstrings b/PAWS/Resources/Localizable.xcstrings index 188ebf9c..7fdb2db5 100644 --- a/PAWS/Resources/Localizable.xcstrings +++ b/PAWS/Resources/Localizable.xcstrings @@ -165,6 +165,9 @@ } } } + }, + "Checkmark: ECG has been successfully uploaded" : { + }, "CLOSE" : { "localizations" : {