From 512429c668b26ab45ec60ad2ff6643d7dc8d0bb3 Mon Sep 17 00:00:00 2001 From: Tobias Reiher <15232394+treiher@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:09:19 +0100 Subject: [PATCH] Add preset muscle filter when replacing exercise in training session --- CHANGELOG.md | 1 + frontend/src/component/exercise_list.rs | 19 +++++++++++++++++++ frontend/src/page/training_session.rs | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e81f5bd..c0248fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/frontend/src/component/exercise_list.rs b/frontend/src/component/exercise_list.rs index 9d36cac..f21af1e 100644 --- a/frontend/src/component/exercise_list.rs +++ b/frontend/src/component/exercise_list.rs @@ -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, + } + } } // ------ ------ diff --git a/frontend/src/page/training_session.rs b/frontend/src/page/training_session.rs index ece33ce..31c1deb 100644 --- a/frontend/src/page/training_session.rs +++ b/frontend/src/page/training_session.rs @@ -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::*, *}; @@ -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) => {