diff --git a/CHANGELOG.md b/CHANGELOG.md index fd03a4e..23d34d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ All notable changes to this project are documented here. - Fixed: progress made on the watch now updates open iPhone screens live. The phone applies a watch-forwarded workout to its cache directly on receipt, instead of waiting on an `NSMetadataQuery` event that a same-process file overwrite - doesn't reliably emit. + doesn't reliably emit — and the exercise detail screen now observes these updates, + so its set grid advances in real time without leaving and re-entering the screen. - Starting a workout on the iPhone now launches the Apple Watch app straight into the session via HealthKit (a one-time Health permission); the watch holds an `HKWorkoutSession` to stay active while you train and releases it when the diff --git a/Workouts/Views/WorkoutLogs/ExerciseView.swift b/Workouts/Views/WorkoutLogs/ExerciseView.swift index 19cd8e5..a74998c 100644 --- a/Workouts/Views/WorkoutLogs/ExerciseView.swift +++ b/Workouts/Views/WorkoutLogs/ExerciseView.swift @@ -63,6 +63,20 @@ struct ExerciseView: View { refreshDocIfNeeded() progress = log?.currentStateIndex ?? 0 } + // Reflect external changes (e.g. a set completed on the watch) live. Each edit + // rewrites the whole workout file, so the cache always holds the latest — pulling + // it in can't revert a newer local tap. + .onChange(of: workout.updatedAt) { _, _ in + absorbExternalUpdate() + } + } + + /// Pull an externally-changed workout into the working copy so the set grid and plan + /// update without leaving and re-entering the screen. + private func absorbExternalUpdate() { + let fresh = WorkoutDocument(from: workout) + doc = fresh + progress = fresh.logs.first(where: { $0.id == logID })?.currentStateIndex ?? progress } @ViewBuilder