GideonNeedleman / 5x5

0 stars 0 forks source link

Make default values adaptive #66

Closed GideonNeedleman closed 10 months ago

GideonNeedleman commented 10 months ago

For adaptive metrics, overwrite default values in programData with the values from your workout upon finishing the workout.

Basically need to copy set metric values from tempWorkoutData to programData on finish workout.

GideonNeedleman commented 10 months ago

Match up set from:

programData[].workouts.exercises[].sets[].id

with:

tempWorkoutData[].setId

Then update metrics values in

programData[].workouts.exercises[].sets[].metrics (.weight or .reps)

With metrics values in

tempWorkoutData[].metrics (.weight or .reps)

Only if metric key is adaptive as matched in

programData[].workouts.exercises[].metrics[].name

With boolean value stored in

programData[].workouts.exercises[].metrics[].adaptive
GideonNeedleman commented 10 months ago

Ok, here's the algorithm. First go to each set in programData programData[].workouts.exercises[].sets[] and check if the id matches with setId of any set in tempWorkoutData: tempWorkoutData[]

If it matches then need to iterate over adaptive metrics by getting list of adaptive metrics in: programData[].workouts.exercises[].metrics[] So essentially go through this array and if .adaptive === true then grab metric NAME from .name and then overwrite programData[].workouts.exercises[].sets[].metrics.NAME with the value in tempWorkoutData[].metrics.NAME

GideonNeedleman commented 10 months ago

Or could I make a copy of the workout (maybe use activeWorkout or a new tempAdaptingWorkout state) and dynamically update the state as I finish sets. Then upon finishing the workout overwrite the workout in programData with the temp workout.

Going to try updating activeWorkout as sets are submitted. 2 possible issues:

  1. activeWorkout was used as a flag to display SelectWorkout or DoWorkout. I switched this to using activeProgramId. Should be functionally equivalent.
  2. Not sure if mutating activeWorkout as we go along will pass through to programData. Is activeWorkout a copy or a reference? If it's a reference then I'll need to make it a copy by doing activeWorkout: {...action.payload.workout} when 'select-workout'