diff --git a/frontend/src/ui/component/exercise_list.rs b/frontend/src/ui/component/exercise_list.rs index 20430cd..9753adc 100644 --- a/frontend/src/ui/component/exercise_list.rs +++ b/frontend/src/ui/component/exercise_list.rs @@ -1,4 +1,6 @@ +use chrono::{Duration, Local}; use seed::{prelude::*, *}; +use std::collections::BTreeSet; use crate::{ domain, @@ -120,20 +122,49 @@ pub fn update(msg: Msg, model: &mut Model, _orders: &mut impl Orders) -> Ou // ------ ------ pub fn view(model: &Model, loading: bool, data_model: &data::Model) -> Vec> { + let cutoff = Local::now().date_naive() - Duration::days(31); let muscle_filter = domain::Muscle::iter() .map(|m| (m, model.filter.muscles.contains(m))) .collect::>(); + let current_exercise_ids = data_model + .training_sessions + .iter() + .filter(|(_, s)| s.date >= cutoff) + .flat_map(|(_, session)| session.exercises()) + .collect::>(); + + let previous_exercise_ids = data_model + .training_sessions + .iter() + .filter(|(_, s)| s.date < cutoff) + .flat_map(|(_, session)| session.exercises()) + .collect::>(); + let exercises = data_model.exercises(&model.filter); - let mut exercises = exercises + + let mut current_exercises = exercises .iter() .filter(|e| { e.name .to_lowercase() .contains(model.search_term.to_lowercase().trim()) + && (current_exercise_ids.contains(&e.id) || !previous_exercise_ids.contains(&e.id)) }) .collect::>(); - exercises.sort_by(|a, b| a.name.cmp(&b.name)); + current_exercises.sort_by(|a, b| a.name.cmp(&b.name)); + + let mut previous_exercises = exercises + .iter() + .filter(|e| { + e.name + .to_lowercase() + .contains(model.search_term.to_lowercase().trim()) + && !current_exercise_ids.contains(&e.id) + && previous_exercise_ids.contains(&e.id) + }) + .collect::>(); + previous_exercises.sort_by(|a, b| a.name.cmp(&b.name)); nodes![ IF![model.view_filter_dialog => view_filter_dialog(&muscle_filter, exercises.len())], @@ -154,7 +185,7 @@ pub fn view(model: &Model, loading: bool, data_model: &data::Model) -> Vec Vec Vec> { + if exercises.is_empty() { + return vec![]; + } + nodes![ + common::view_title(&span![title], 1), div![ C!["table-container"], C!["mt-2"], @@ -253,7 +295,7 @@ pub fn view(model: &Model, loading: bool, data_model: &data::Model) -> Vec