Fix: per-date workout completion in calendar (KC-10)

The calendar marked every occurrence of a program complete once any one
was finished — including future dates — because DayTimelineView read the
program's live shared doneSets.

- Add WorkoutViewModel.isWorkoutComplete(on:) backed by workoutDates.
- DayTimelineView takes workoutDone and uses it instead of live sets;
  Calendar passes the selected date's state, Today passes today's.
- A date now shows complete only if that specific date was finished.

Log KC-10 in ISSUES.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kutesir
2026-06-08 00:29:48 +03:00
parent 966c1b35e9
commit d09a6c1fe3
4 changed files with 43 additions and 2 deletions

View File

@@ -587,6 +587,7 @@ struct CalendarView: View {
},
calEvents: calStore.isAuthorized ? calStore.events(for: selectedDate) : [],
workout: workoutVM.program(for: selectedDate),
workoutDone: workoutVM.isWorkoutComplete(on: selectedDate),
onWorkoutTap: {
if let w = workoutVM.program(for: selectedDate),
workoutVM.activeProgramId != w.id { workoutVM.switchProgram(to: w.id) }
@@ -1538,6 +1539,7 @@ struct DayTimelineView: View {
var overdueTasks: [TaskItem] = []
let calEvents: [EKEvent]
let workout: WorkoutProgram?
var workoutDone: Bool = false // per-DATE completion (from workoutDates), not live sets
var onWorkoutTap: (() -> Void)? = nil
var onToggle: ((TaskItem) -> Void)? = nil
var onPin: ((TaskItem) -> Void)? = nil
@@ -1583,9 +1585,10 @@ struct DayTimelineView: View {
))
}
// Workout always pinned first (sortGroup -1)
// Workout always pinned first (sortGroup -1). Completion is tied to THIS
// date (workoutDates), never the program's shared live set state.
if let w = workout {
let done = w.doneSets == w.totalSets && w.totalSets > 0
let done = workoutDone
out.append(DayTLEntry(
timeLabel: "Workout",
title: w.name,

View File

@@ -90,6 +90,7 @@ struct TodayView: View {
overdueTasks: [],
calEvents: todayCalEvents,
workout: workoutVM.program(for: Date()),
workoutDone: workoutVM.isWorkoutComplete(on: Date()),
onWorkoutTap: {
if let w = workoutVM.program(for: Date()), workoutVM.activeProgramId != w.id {
workoutVM.switchProgram(to: w.id)