Skip to content

Commit

Permalink
Add function to insert values of previous set
Browse files Browse the repository at this point in the history
  • Loading branch information
senier authored and treiher committed Oct 21, 2024
1 parent 83ed35e commit 3d735ae
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
100 changes: 100 additions & 0 deletions frontend/src/page/training_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -328,6 +354,10 @@ struct ExerciseForm {
prev_time: Option<u32>,
prev_weight: Option<f32>,
prev_rpe: Option<f32>,
prev_set_reps: Option<u32>,
prev_set_time: Option<u32>,
prev_set_weight: Option<f32>,
prev_set_rpe: Option<f32>,
automatic: bool,
}

Expand Down Expand Up @@ -662,6 +692,7 @@ pub enum Msg {

EnterTargetValues(usize, usize),
EnterPreviousValues(usize, usize),
EnterPreviousSetValues(usize, usize),

StartGuidedTrainingSession,
ContinueGuidedTrainingSession(data::OngoingTrainingSession),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1618,6 +1684,10 @@ fn add_set(elements: &mut Vec<FormElement>, 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::<Vec<_>>(),
Expand Down Expand Up @@ -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,
},
);
Expand Down Expand Up @@ -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,
}],
});
Expand Down Expand Up @@ -2237,6 +2315,13 @@ fn view_training_session_form(model: &Model, data_model: &data::Model) -> Vec<No
s.prev_weight,
s.prev_rpe,
data_model.settings.show_rpe);
let previous_set = common::format_set(
s.prev_set_reps,
s.prev_set_time,
data_model.settings.show_tut,
s.prev_set_weight,
s.prev_set_rpe,
data_model.settings.show_rpe);
p![
IF![not(target.is_empty()) =>
span![
Expand All @@ -2260,6 +2345,17 @@ fn view_training_session_form(model: &Model, data_model: &data::Model) -> Vec<No
]
]
],
IF![not(previous_set.is_empty()) =>
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![
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 3d735ae

Please sign in to comment.