Skip to content

Commit

Permalink
Add preset muscle filter when replacing exercise in training session
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Nov 1, 2024
1 parent 09a9048 commit 512429c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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
- Suggestion of exercises that train similar muscles when replacing exercise in training session

### Changed

Expand Down
19 changes: 19 additions & 0 deletions frontend/src/component/exercise_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ impl Model {
search_bar_padding,
}
}

#[allow(clippy::fn_params_excessive_bools)]
pub fn new_with_filter(
view_create: bool,
view_edit: bool,
view_delete: bool,
search_bar_padding: bool,
filter: domain::ExerciseFilter,
) -> Self {
Self {
search_term: String::new(),
filter,
view_filter_dialog: false,
view_create,
view_edit,
view_delete,
search_bar_padding,
}
}
}

// ------ ------
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/page/training_session.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, HashMap, HashSet};

use chrono::{prelude::*, Duration};
use seed::{prelude::*, *};
Expand Down Expand Up @@ -1203,10 +1203,25 @@ pub fn update(
model.dialog = Dialog::Options(element_idx, exercise_idx);
}
Msg::ShowReplaceExerciseDialog(element_idx, exercise_idx) => {
let mut muscles = HashSet::new();
if let FormElement::Set { exercises } = &mut model.form.elements[element_idx] {
let exercise_id = exercises[exercise_idx].exercise_id;
for m in &data_model.exercises[&exercise_id].muscles {
if let Some(muscle) = domain::Muscle::from_repr(m.muscle_id) {
muscles.insert(muscle);
}
}
}
model.dialog = Dialog::ReplaceExercise(
element_idx,
exercise_idx,
component::exercise_list::Model::new(true, false, false, false),
component::exercise_list::Model::new_with_filter(
true,
false,
false,
false,
domain::ExerciseFilter { muscles },
),
);
}
Msg::ShowAddExerciseDialog(element_idx, exercise_idx) => {
Expand Down

0 comments on commit 512429c

Please sign in to comment.