ivanscorral / ivanscorral/KoWorkout

Add Exercise To Workout (from Workout Detail)

Open
#1 0 comments 0 reactions 1 assignee View on GitHub

@ivanscorral is already working on this.

Since Oct 12, 2025.

enhancement
Dominant language
Swift
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

### Summary
Wire the **plus button** in `KoWorkout/Views/WorkoutDetailView.swift:18-23` to add an exercise to the current workout by selecting from the exercise library (and optionally creating a new exercise).

---

### Data Layer
Add `WorkoutRepository` and `InMemoryWorkoutRepository` to manage `Workout` mutations (align with `ExerciseRepository`).

**Protocol (minimal):**
```swift
@MainActor
protocol WorkoutRepository: AnyObject {
func get(_ id: UUID) -> Workout?
func update(_ id: UUID, _ mutate: (inout Workout) -> Void)
}
```

### Convenience:
```swift
func addExercise(to id: UUID, exercise: Exercise, notes: String? = nil, order: Int? = nil)
```

> **Note:** A repository is required because `WorkoutDetailViewModel` currently owns a value copy of `Workout` and has no mutation pathways.

---

### ViewModel
Update `WorkoutDetailViewModel` to:
- Accept `workoutId: UUID`, `workoutRepository: WorkoutRepository`, and `exerciseRepository: ExerciseRepository`.
- Add state `isPresentingExercisePicker: Bool` and action `presentExercisePicker()`.
- Add action `addExercise(_ exercise: Exercise)` that:
- Calls `workoutRepository.addExercise(to: workoutId, exercise: exercise)`
- Refreshes display state from repository.
- Update initializer and `updateWorkout(_:)` to hydrate from repository.

---

### UI/UX
From `WorkoutDetailView.swift:18-23`:
- Present a **sheet** when tapping the plus button — an `ExercisePickerView` (new) that lists library exercises using `ExerciseListViewModel` / `ExerciseRepository`.

**In the picker:**
- Selecting an existing exercise → calls `viewModel.addExercise(selectedExercise)`
- Creating a new exercise via `AddExerciseView` → select it manually or auto-select on save.

---

### Acceptance Criteria
- ✅ Tapping **plus** opens a picker
- ✅ Choosing an exercise inserts it into the workout and updates the UI immediately (in correct order)
- ✅ When the workout has no exercises, adding one hides the empty state (`KoWorkout/Views/WorkoutDetailView.swift:233-241`)
- ✅ Previews continue to compile with an in-memory repository (provide preview fixtures)

---

### Files To Touch
- `KoWorkout/Views/WorkoutDetailView.swift:18-23`
- `KoWorkout/ViewModels/WorkoutDetailViewModel.swift:12` (constructor), `:69` (state), and add new actions
- **New:** `KoWorkout/Repositories/WorkoutRepository.swift`
- **New:** `KoWorkout/Views/ExercisePickerView.swift` *(or adapt `ExerciseListView` to support selection mode)*

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.