Files
workouts/Workouts/Views/Exercises/ExerciseDocument+PlanSummary.swift
T
rzen 36dad21233 Add pure helpers for routine ordering, copy naming, and a grouped exercise catalog
Groundwork for the Library tab: RoutineOrdering.changedOrders turns an
.onMove gesture into the minimal set of order writes (normalizing legacy
colliding orders on first drag), RoutineNaming.uniqueName picks the next
free "X Copy" name for duplication, and ExerciseCatalog groups the bundled
exercise library into curated category sections with name/category/target
search. Plus ExerciseDocument.planSummary for read-only document rendering.
All covered by unit tests, including a motion/info name-parity assertion.

Claude-Session: https://claude.ai/code/session_01H8VxUX4ckjU3vRF5M4L5FV
2026-07-15 10:38:43 -04:00

29 lines
1.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ExerciseDocument+PlanSummary.swift
// Workouts
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//
import Foundation
extension ExerciseDocument {
/// One-line plan summary for list rows — mirrors `Exercise.planSummary(weightUnit:)`
/// (`Shared/Model/Entities.swift`) exactly, but works from the on-disk document
/// rather than the SwiftData cache entity: duration exercises show their hold time
/// ("3 × 45 sec"), unloaded ones drop the weight ("3 × 12 reps"), weighted ones keep
/// the full "3 × 10 × 40 lb".
func planSummary(weightUnit: WeightUnit) -> String {
switch LoadType(rawValue: loadType) ?? .weight {
case .duration:
let m = durationSeconds / 60, s = durationSeconds % 60
let hold = m > 0 && s > 0 ? "\(m)m \(s)s" : (m > 0 ? "\(m) min" : "\(s) sec")
return "\(sets) × \(hold)"
case .none:
return "\(sets) × \(reps) reps"
case .weight:
return "\(sets) × \(reps) × \(weightUnit.format(weight))"
}
}
}