Refresh the exercise detail screen live on external workout changes
ExerciseView now observes workout.updatedAt and pulls the latest doc/progress from the cache, mirroring WorkoutLogListView. A set completed on the watch now advances the iPhone set grid in real time instead of only on re-entry. Claude-Session: https://claude.ai/code/session_018gg69MaUetDNzWzBXisfMV
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user