Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only dismiss the measurements sheet when we are saving the last one #12

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
public var body: some View {
NavigationStack {
Group {
if measurements.pendingMeasurements.isEmpty {
if measurements.pendingMeasurements.isEmpty && selectedMeasurement == nil {
ContentUnavailableView(
"No Pending Measurements",
systemImage: "heart.text.square",
Expand Down Expand Up @@ -120,7 +120,7 @@
}
.tabViewStyle(.page)
.indexViewStyle(.page(backgroundDisplayMode: .always))
} else if let measurement = measurements.pendingMeasurements.first {
} else if let measurement = selectedMeasurement {
MeasurementLayer(measurement: measurement)
}
}
Expand All @@ -140,7 +140,6 @@


logger.info("Saved measurement: \(String(describing: selectedMeasurement))")
dismiss()

discardSelectedMeasurement(selectedMeasurement)
} discard: {
Expand All @@ -149,10 +148,6 @@
}

discardSelectedMeasurement(selectedMeasurement)

if measurements.pendingMeasurements.isEmpty {
dismiss()
}
}
}

Expand All @@ -170,19 +165,27 @@
}

measurements.discardMeasurement(measurement)
if index >= measurements.pendingMeasurements.count {
selectedMeasurement = measurements.pendingMeasurements.last
} else {

if index < measurements.pendingMeasurements.count {
selectedMeasurement = measurements.pendingMeasurements[index]
} else if let last = measurements.pendingMeasurements.last {
// we do not set `selectedMeasurement` to nil if we are discarding the last measurement to have the
// last measurement still display when the sheet is in its dismiss animation.
selectedMeasurement = last

Check warning on line 174 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift#L172-L174

Added lines #L172 - L174 were not covered by tests
}

if measurements.pendingMeasurements.isEmpty {
dismiss()
}
}
}


#if DEBUG
#Preview {
Text(verbatim: "")
.sheet(isPresented: .constant(true)) {
@State var isPresented = true

Check warning on line 186 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 186 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 186 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 186 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -193,8 +196,9 @@
}

#Preview {
Text(verbatim: "")
.sheet(isPresented: .constant(true)) {
@State var isPresented = true

Check warning on line 199 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 199 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 199 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 199 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -205,8 +209,9 @@
}

#Preview {
Text(verbatim: "")
.sheet(isPresented: .constant(true)) {
@State var isPresented = true

Check warning on line 212 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 212 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 212 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 212 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -217,8 +222,9 @@
}

#Preview {
Text(verbatim: "")
.sheet(isPresented: .constant(true)) {
@State var isPresented = true

Check warning on line 225 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 225 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 225 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 225 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -233,8 +239,9 @@
}

#Preview {
Text(verbatim: "")
.sheet(isPresented: .constant(true)) {
@State var isPresented = true

Check warning on line 242 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 242 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 242 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'

Check warning on line 242 in Sources/SpeziDevicesUI/Measurements/MeasurementsRecordedSheet.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@State' used inline will not work unless tagged with '@Previewable'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand Down
Loading