Restructure into a three-tab app with Progress, goals, and Meditation
The UX redesign's first landing (spec in UX-REDESIGN.md): ContentView becomes a Today / Progress / Settings TabView, "Routine" replaces "Split" in every user-facing string and view name (code-level types keep their names), and workout starting moves to shared WorkoutStarter / StartedWorkoutNavigator plumbing. - New Progress tab: weekly goal streaks, workout trends, per-exercise weight progression, achievements, and the full history list (WorkoutLogsView -> WorkoutHistoryView). - Goals: stable categories workouts roll up to, managed from Settings. - New Meditation exercise + starter routine; timed sits record to Apple Health as Mind & Body sessions. Claude-Session: https://claude.ai/code/session_012qw2itfzKyEJ1HpsFt8Ex4
This commit is contained in:
@@ -11,7 +11,7 @@ import SwiftData
|
||||
/// Root of the watch app. The watch only runs the workouts that are currently
|
||||
/// active on the phone — there's no history browsing here. An "active" workout is a
|
||||
/// cached one that isn't finished (`notStarted` or `inProgress`); a workout is
|
||||
/// created on the phone as `notStarted` the moment a split is picked, and flips to
|
||||
/// created on the phone as `notStarted` the moment a routine is picked, and flips to
|
||||
/// `completed` once every exercise is done, at which point it drops off this list.
|
||||
///
|
||||
/// The root shows every active workout (most-recent first); picking one opens its
|
||||
@@ -20,7 +20,7 @@ struct ActiveWorkoutGateView: View {
|
||||
@Environment(WatchConnectivityBridge.self) private var bridge
|
||||
|
||||
@Query(sort: \Workout.start, order: .reverse) private var workouts: [Workout]
|
||||
@Query private var splits: [Split]
|
||||
@Query private var routines: [Routine]
|
||||
|
||||
/// Navigated workouts (depth 1). Held here — rather than relying on implicit
|
||||
/// `NavigationLink` destinations — so we can pop back to the gate the moment the phone
|
||||
@@ -31,17 +31,17 @@ struct ActiveWorkoutGateView: View {
|
||||
workouts.filter { $0.status == .inProgress || $0.status == .notStarted }
|
||||
}
|
||||
|
||||
private func split(for workout: Workout) -> Split? {
|
||||
guard let id = workout.splitID else { return nil }
|
||||
return splits.first { $0.id == id }
|
||||
private func routine(for workout: Workout) -> Routine? {
|
||||
guard let id = workout.routineID else { return nil }
|
||||
return routines.first { $0.id == id }
|
||||
}
|
||||
|
||||
/// True while the phone has this workout's exercise — or the split it came from — open
|
||||
/// True while the phone has this workout's exercise — or the routine it came from — open
|
||||
/// in an editor. The watch parks such a run and blocks re-entry so the phone owns the
|
||||
/// edit and the watch can't forward a stale optimistic write over it.
|
||||
private func isLockedForEditing(_ workout: Workout) -> Bool {
|
||||
if let id = bridge.editingWorkoutID, id == workout.id { return true }
|
||||
if let splitID = bridge.editingSplitID, splitID == workout.splitID { return true }
|
||||
if let routineID = bridge.editingRoutineID, routineID == workout.routineID { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -89,17 +89,17 @@ struct ActiveWorkoutGateView: View {
|
||||
// pop back to the gate so re-entry rebuilds a fresh working copy. Also pop if the run
|
||||
// we're inside was pruned (discarded/deleted on the phone, or aged out of the push).
|
||||
.onChange(of: bridge.editingWorkoutID) { _, _ in popIfNavigatedRunUnavailable() }
|
||||
.onChange(of: bridge.editingSplitID) { _, _ in popIfNavigatedRunUnavailable() }
|
||||
.onChange(of: bridge.editingRoutineID) { _, _ in popIfNavigatedRunUnavailable() }
|
||||
.onChange(of: workouts.map(\.id)) { _, _ in popIfNavigatedRunUnavailable() }
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func row(for workout: Workout) -> some View {
|
||||
if isLockedForEditing(workout) {
|
||||
ActiveWorkoutRow(workout: workout, split: split(for: workout), editingOnPhone: true)
|
||||
ActiveWorkoutRow(workout: workout, routine: routine(for: workout), editingOnPhone: true)
|
||||
} else {
|
||||
NavigationLink(value: ActiveWorkoutRoute(workoutID: workout.id)) {
|
||||
ActiveWorkoutRow(workout: workout, split: split(for: workout))
|
||||
ActiveWorkoutRow(workout: workout, routine: routine(for: workout))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ struct ActiveWorkoutGateView: View {
|
||||
|
||||
private struct ActiveWorkoutRow: View {
|
||||
let workout: Workout
|
||||
let split: Split?
|
||||
let routine: Routine?
|
||||
/// When true, the phone is editing this run — render it dimmed and non-tappable.
|
||||
var editingOnPhone: Bool = false
|
||||
|
||||
@@ -144,13 +144,13 @@ private struct ActiveWorkoutRow: View {
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: editingOnPhone ? "pencil" : (split?.systemImage ?? "figure.strengthtraining.traditional"))
|
||||
Image(systemName: editingOnPhone ? "pencil" : (routine?.systemImage ?? "figure.strengthtraining.traditional"))
|
||||
.font(.title3)
|
||||
.foregroundStyle(split.map { Color.color(from: $0.color) } ?? .workTint)
|
||||
.foregroundStyle(routine.map { Color.color(from: $0.color) } ?? .workTint)
|
||||
.frame(width: 26)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(workout.splitName ?? Split.unnamed)
|
||||
Text(workout.routineName ?? Routine.unnamed)
|
||||
.font(.headline)
|
||||
.lineLimit(1)
|
||||
|
||||
|
||||
@@ -163,11 +163,11 @@ struct ExerciseProgressView: View {
|
||||
/// page-index math below depends on it.
|
||||
private var showsReady: Bool { debugInitialPage == nil && !enteredViaFlow }
|
||||
|
||||
/// This split runs as a continuous flow — finishing one exercise rests, then
|
||||
/// This routine runs as a continuous flow — finishing one exercise rests, then
|
||||
/// auto-advances into the next — rather than returning to the list per exercise.
|
||||
private var autoAdvance: Bool { doc.autoAdvance == true }
|
||||
|
||||
/// Rest length for this run: the split's per-split override, else the global default.
|
||||
/// Rest length for this run: the routine's per-routine override, else the global default.
|
||||
/// Governs both between-set rests and (in flow mode) the between-exercise rest.
|
||||
private var effectiveRest: Int { max(1, doc.restSeconds ?? restSeconds) }
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Thin coordinator that lets a single pushed run walk across exercises in a flow-mode
|
||||
/// split (`autoAdvance`). It owns which log is on screen and swaps it when the running
|
||||
/// routine (`autoAdvance`). It owns which log is on screen and swaps it when the running
|
||||
/// `ExerciseProgressView` finishes an exercise; `.id(currentLogID)` rebuilds the child
|
||||
/// fresh for each exercise, so the delicate per-exercise run/mirror machinery stays
|
||||
/// exactly as it is. For a non-flow split it's transparent — one exercise, unchanged.
|
||||
/// exactly as it is. For a non-flow routine it's transparent — one exercise, unchanged.
|
||||
struct RunFlowView: View {
|
||||
@Environment(WatchConnectivityBridge.self) private var bridge
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ struct WorkoutLogListView: View {
|
||||
_doc = State(initialValue: WorkoutDocument(fromLive: workout) ?? .deletedPlaceholder)
|
||||
}
|
||||
|
||||
/// The split this workout came from (read-only on the watch), used to offer
|
||||
/// The routine this workout came from (read-only on the watch), used to offer
|
||||
/// additional exercises that aren't logged yet. Fetched imperatively — *not* via
|
||||
/// `@Query` — so the list body never observes the live `Split` or traverses its
|
||||
/// `@Query` — so the list body never observes the live `Routine` or traverses its
|
||||
/// `exercises` relationship during a render. Doing so (a `@Query`-observed model
|
||||
/// whose to-many relationship is read in `body`) drove a SwiftData re-render loop
|
||||
/// that hung the watch. `availableExercises` is therefore only ever evaluated from
|
||||
/// the picker sheet's closure, not from `body`.
|
||||
private var split: Split? {
|
||||
guard let splitID = doc.splitID else { return nil }
|
||||
return CacheMapper.fetchSplit(id: splitID, in: modelContext)
|
||||
private var routine: Routine? {
|
||||
guard let routineID = doc.routineID else { return nil }
|
||||
return CacheMapper.fetchRoutine(id: routineID, in: modelContext)
|
||||
}
|
||||
|
||||
private var sortedLogs: [WorkoutLogDocument] {
|
||||
@@ -52,9 +52,9 @@ struct WorkoutLogListView: View {
|
||||
}
|
||||
|
||||
private var availableExercises: [Exercise] {
|
||||
guard let split else { return [] }
|
||||
guard let routine else { return [] }
|
||||
let existingNames = Set(doc.logs.map { $0.exerciseName })
|
||||
return split.exercisesArray.filter { !existingNames.contains($0.name) }
|
||||
return routine.exercisesArray.filter { !existingNames.contains($0.name) }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -74,10 +74,10 @@ struct WorkoutLogListView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// Gate on the *resolved* split, not the stale `splitID` string — a split
|
||||
// Gate on the *resolved* routine, not the stale `routineID` string — a routine
|
||||
// deleted on the phone leaves the id dangling, and offering Add Exercise
|
||||
// against it would only show a misleading "All exercises added" picker.
|
||||
if split != nil {
|
||||
if routine != nil {
|
||||
Section {
|
||||
Button {
|
||||
showingExercisePicker = true
|
||||
@@ -96,13 +96,13 @@ struct WorkoutLogListView: View {
|
||||
ContentUnavailableView(
|
||||
"No Exercises",
|
||||
systemImage: "figure.strengthtraining.traditional",
|
||||
description: Text(split == nil
|
||||
description: Text(routine == nil
|
||||
? "No exercises in this workout."
|
||||
: "Tap + to add exercises.")
|
||||
)
|
||||
}
|
||||
}
|
||||
.navigationTitle(doc.splitName ?? Split.unnamed)
|
||||
.navigationTitle(doc.routineName ?? Routine.unnamed)
|
||||
// Absorb phone edits while this screen is open (H1's watch-side gap):
|
||||
// without this, the snapshot stays frozen at init, and the next watch
|
||||
// tick — made against a state that's missing the phone's edit — would be
|
||||
@@ -120,7 +120,7 @@ struct WorkoutLogListView: View {
|
||||
}
|
||||
}
|
||||
.navigationDestination(item: $selectedLogID) { logID in
|
||||
// RunFlowView hosts the run and, in a flow-mode split, auto-advances across
|
||||
// RunFlowView hosts the run and, in a flow-mode routine, auto-advances across
|
||||
// exercises. It owns the live-run mirror wiring (incoming-frame filter,
|
||||
// `navigatedRunID`, and the parameterized live-ended signal) since the on-screen
|
||||
// log advances during a flowing run.
|
||||
|
||||
Reference in New Issue
Block a user