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
29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
//
|
||
// 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))"
|
||
}
|
||
}
|
||
}
|