Skip to content

Commit

Permalink
Only dismiss the measurements sheet when we are saving the last one (#12
Browse files Browse the repository at this point in the history
)

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

## ♻️ Current situation & Problem
This PR address StanfordBDHG/ENGAGE-HF-iOS#79
by only dismissing the recorded measurements sheet only if there aren't
any more measurements displayed. This makes it easier for users to save
multiple measurements.

## ⚙️ Release Notes 
* Only dismiss the measurements sheet if the last measurement is saved.
*  Show the last measurement in the closing animation.

## 📚 Documentation
--


## ✅ Testing
Existing test validate this behavior.

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Sep 2, 2024
1 parent cfba769 commit dc8dcd5
Showing 1 changed file with 27 additions and 20 deletions.
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 struct MeasurementsRecordedSheet: View {
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 @@ public struct MeasurementsRecordedSheet: View {
}
.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 @@ public struct MeasurementsRecordedSheet: View {


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

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

discardSelectedMeasurement(selectedMeasurement)

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

Expand All @@ -170,19 +165,27 @@ public struct MeasurementsRecordedSheet: View {
}

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
}

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 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'

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'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -193,8 +196,9 @@ public struct MeasurementsRecordedSheet: View {
}

#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 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'

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'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -205,8 +209,9 @@ public struct MeasurementsRecordedSheet: View {
}

#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 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'

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'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -217,8 +222,9 @@ public struct MeasurementsRecordedSheet: View {
}

#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 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'

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'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand All @@ -233,8 +239,9 @@ public struct MeasurementsRecordedSheet: View {
}

#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 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'

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'
return Text(verbatim: "")
.sheet(isPresented: $isPresented) {
MeasurementsRecordedSheet { samples in
print("Saving samples \(samples)")
}
Expand Down

0 comments on commit dc8dcd5

Please sign in to comment.