diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7eb7c..06c6804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Button for saving changes during guided training session - Settings for hiding UI elements related to RPE and TUT - Option to prefer exercise in training session +- Shortcut for inserting values of previous set into current set ### Changed diff --git a/frontend/src/page/training_session.rs b/frontend/src/page/training_session.rs index d5550a3..9cc9b5a 100644 --- a/frontend/src/page/training_session.rs +++ b/frontend/src/page/training_session.rs @@ -139,6 +139,28 @@ fn init_form(training_session: Option<&data::TrainingSession>, data_model: &data } else { (None, None, None, None) }; + + let (prev_set_reps, prev_set_time, prev_set_weight, prev_set_rpe) = + if let Some(prev_set) = elements + .iter() + .filter_map(|e| match e { + FormElement::Set { exercises } => Some(exercises), + _ => None, + }) + .flatten() + .filter(|pe| pe.exercise_id == *exercise_id) + .last() + { + ( + prev_set.reps.parsed.filter(|v| *v > 0), + prev_set.time.parsed.filter(|v| *v > 0), + prev_set.weight.parsed.filter(|v| *v > 0.), + prev_set.rpe.parsed.filter(|v| *v > 0.), + ) + } else { + (None, None, None, None) + }; + exercises.push(ExerciseForm { exercise_id: *exercise_id, exercise_name: data_model @@ -173,6 +195,10 @@ fn init_form(training_session: Option<&data::TrainingSession>, data_model: &data prev_time, prev_weight, prev_rpe, + prev_set_reps, + prev_set_time, + prev_set_weight, + prev_set_rpe, automatic: *automatic, }); if target_time.is_some() && target_reps.is_none() { @@ -328,6 +354,10 @@ struct ExerciseForm { prev_time: Option, prev_weight: Option, prev_rpe: Option, + prev_set_reps: Option, + prev_set_time: Option, + prev_set_weight: Option, + prev_set_rpe: Option, automatic: bool, } @@ -662,6 +692,7 @@ pub enum Msg { EnterTargetValues(usize, usize), EnterPreviousValues(usize, usize), + EnterPreviousSetValues(usize, usize), StartGuidedTrainingSession, ContinueGuidedTrainingSession(data::OngoingTrainingSession), @@ -884,6 +915,41 @@ pub fn update( }; } } + Msg::EnterPreviousSetValues(element_idx, exercise_idx) => { + if let FormElement::Set { exercises } = &mut model.form.elements[element_idx] { + let ExerciseForm { + reps, + time, + weight, + rpe, + prev_set_reps, + prev_set_time, + prev_set_weight, + prev_set_rpe, + .. + } = &mut exercises[exercise_idx]; + *reps = common::InputField { + input: prev_set_reps.map(|v| v.to_string()).unwrap_or_default(), + parsed: some_or_default(*prev_set_reps), + orig: reps.orig.clone(), + }; + *time = common::InputField { + input: prev_set_time.map(|v| v.to_string()).unwrap_or_default(), + parsed: some_or_default(*prev_set_time), + orig: time.orig.clone(), + }; + *weight = common::InputField { + input: prev_set_weight.map(|v| v.to_string()).unwrap_or_default(), + parsed: some_or_default(*prev_set_weight), + orig: weight.orig.clone(), + }; + *rpe = common::InputField { + input: prev_set_rpe.map(|v| v.to_string()).unwrap_or_default(), + parsed: some_or_default(*prev_set_rpe), + orig: rpe.orig.clone(), + }; + } + } Msg::StartGuidedTrainingSession => { model.guide = Some(Guide::new(data_model.settings.beep_volume)); @@ -1618,6 +1684,10 @@ fn add_set(elements: &mut Vec, element_idx: usize) { prev_time: None, prev_weight: None, prev_rpe: None, + prev_set_reps: None, + prev_set_time: None, + prev_set_weight: None, + prev_set_rpe: None, automatic: e.automatic, }) .collect::>(), @@ -1662,6 +1732,10 @@ fn add_exercise( prev_time: None, prev_weight: None, prev_rpe: None, + prev_set_reps: None, + prev_set_time: None, + prev_set_weight: None, + prev_set_rpe: None, automatic: false, }, ); @@ -1734,6 +1808,10 @@ fn append_exercise( prev_time: None, prev_weight: None, prev_rpe: None, + prev_set_reps: None, + prev_set_time: None, + prev_set_weight: None, + prev_set_rpe: None, automatic: false, }], }); @@ -2237,6 +2315,13 @@ fn view_training_session_form(model: &Model, data_model: &data::Model) -> Vec span![ @@ -2260,6 +2345,17 @@ fn view_training_session_form(model: &Model, data_model: &data::Model) -> Vec + span![ + C!["icon-text"], + C!["mr-4"], + span![C!["icon"], i![C!["fas fa-angle-double-up"]]], + a![ + ev(Ev::Click, move |_| Msg::EnterPreviousSetValues(element_idx, position)), + previous_set + ] + ] + ], IF![ s.automatic => span![ @@ -4771,6 +4867,10 @@ mod tests { prev_time: None, prev_weight: None, prev_rpe: None, + prev_set_reps: None, + prev_set_time: None, + prev_set_weight: None, + prev_set_rpe: None, automatic: false, } }