Workout: auto-switch to today's program + Rest Day state
The Workout tab kept showing the last-used program (with its old completion) regardless of the weekly schedule, so a rest day still displayed a stale, fully-checked workout. - On a new day, the active program now follows the weekly schedule (applyScheduledProgramForToday in resetSetsForNewDayIfNeeded). - Add isRestDayToday + a Rest Day card shown when today has no scheduled program, with a "Work out anyway" override. Header reads "Rest Day". - Daily set reset (KC-1) unchanged — no day starts pre-checked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -313,10 +313,32 @@ class WorkoutViewModel: ObservableObject {
|
||||
let today = iso.string(from: Date())
|
||||
let last = UserDefaults.kisani.string(forKey: kLastActiveDay)
|
||||
guard last != today else { return }
|
||||
if last != nil { clearAllDoneSets() } // skip the wipe on the very first launch
|
||||
if last != nil {
|
||||
clearAllDoneSets() // skip the wipe on the very first launch
|
||||
applyScheduledProgramForToday() // follow the weekly schedule on a new day
|
||||
}
|
||||
UserDefaults.kisani.set(today, forKey: kLastActiveDay)
|
||||
}
|
||||
|
||||
/// The program assigned to today in the weekly schedule (nil = rest day).
|
||||
var todaysScheduledProgram: WorkoutProgram? { program(for: Date()) }
|
||||
|
||||
/// True when a schedule exists but today has no program — a rest day.
|
||||
var isRestDayToday: Bool {
|
||||
let weekday = Calendar.current.component(.weekday, from: Date())
|
||||
return !schedule.isEmpty && schedule[weekday] == nil
|
||||
}
|
||||
|
||||
/// On a new day, make the active program match the day's schedule so the
|
||||
/// Workout tab shows today's workout instead of yesterday's. Rest days leave
|
||||
/// the active program untouched (the view shows a rest state instead).
|
||||
private func applyScheduledProgramForToday() {
|
||||
guard let scheduled = todaysScheduledProgram, scheduled.id != activeProgramId else { return }
|
||||
activeProgramId = scheduled.id
|
||||
activeSections = scheduled.sections
|
||||
save()
|
||||
}
|
||||
|
||||
/// Unchecks every set across all programs and clears the in-progress session.
|
||||
private func clearAllDoneSets() {
|
||||
for pi in programs.indices {
|
||||
|
||||
Reference in New Issue
Block a user