diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c6804..e81f5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Omit charts that contain no data - Hide empty columns in training tables - Consider sets without RPE value to be hard sets +- Default interval on exercise, body weight, body fat and menstrual cycle page to three months ### Fixed diff --git a/frontend/src/common.rs b/frontend/src/common.rs index f353462..0797bc9 100644 --- a/frontend/src/common.rs +++ b/frontend/src/common.rs @@ -39,6 +39,15 @@ impl From> for Interval { } } +#[derive(Clone, Copy, PartialEq)] +pub enum DefaultInterval { + All, + _1Y = 365, + _6M = 182, + _3M = 91, + _1M = 30, +} + #[derive(Clone)] #[cfg_attr(test, derive(Debug, PartialEq))] pub struct InputField { @@ -67,13 +76,15 @@ impl InputField { } } -pub fn init_interval(dates: &[NaiveDate], show_all: bool) -> Interval { +pub fn init_interval(dates: &[NaiveDate], default_interval: DefaultInterval) -> Interval { let today = Local::now().date_naive(); let mut first = dates.iter().copied().min().unwrap_or(today); let mut last = dates.iter().copied().max().unwrap_or(today); - if not(show_all) && last >= today - Duration::days(30) { - first = today - Duration::days(30); + if default_interval != DefaultInterval::All + && last >= today - Duration::days(default_interval as i64) + { + first = today - Duration::days(default_interval as i64); }; last = today; @@ -268,27 +279,27 @@ where ), ( "1Y", - today - Duration::days(365), + today - Duration::days(DefaultInterval::_1Y as i64), today, - current.last == today && duration == Duration::days(366), + current.last == today && duration == Duration::days(DefaultInterval::_1Y as i64 + 1), ), ( "6M", - today - Duration::days(182), + today - Duration::days(DefaultInterval::_6M as i64), today, - current.last == today && duration == Duration::days(183), + current.last == today && duration == Duration::days(DefaultInterval::_6M as i64 + 1), ), ( "3M", - today - Duration::days(91), + today - Duration::days(DefaultInterval::_3M as i64), today, - current.last == today && duration == Duration::days(92), + current.last == today && duration == Duration::days(DefaultInterval::_3M as i64 + 1), ), ( "1M", - today - Duration::days(30), + today - Duration::days(DefaultInterval::_1M as i64), today, - current.last == today && duration == Duration::days(31), + current.last == today && duration == Duration::days(DefaultInterval::_1M as i64 + 1), ), ( "+", diff --git a/frontend/src/page/body_fat.rs b/frontend/src/page/body_fat.rs index 873e75e..af83677 100644 --- a/frontend/src/page/body_fat.rs +++ b/frontend/src/page/body_fat.rs @@ -29,7 +29,7 @@ pub fn init( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ), dialog: Dialog::Hidden, loading: false, @@ -418,7 +418,7 @@ pub fn update( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ); } data::Event::BodyFatCreatedOk diff --git a/frontend/src/page/body_weight.rs b/frontend/src/page/body_weight.rs index c739b32..5d54039 100644 --- a/frontend/src/page/body_weight.rs +++ b/frontend/src/page/body_weight.rs @@ -33,7 +33,7 @@ pub fn init( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ), dialog: Dialog::Hidden, loading: false, @@ -195,7 +195,7 @@ pub fn update( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ); } data::Event::BodyWeightCreatedOk diff --git a/frontend/src/page/exercise.rs b/frontend/src/page/exercise.rs index 9bc6782..fe6aa12 100644 --- a/frontend/src/page/exercise.rs +++ b/frontend/src/page/exercise.rs @@ -30,7 +30,7 @@ pub fn init( navbar.title = String::from("Exercise"); let mut model = Model { - interval: common::init_interval(&[], true), + interval: common::init_interval(&[], common::DefaultInterval::_3M), exercise_id, name: common::InputField::default(), muscle_stimulus: BTreeMap::new(), @@ -216,7 +216,7 @@ fn update_model(model: &mut Model, data_model: &data::Model) { .filter(|t| t.exercises().contains(&model.exercise_id)) .map(|t| t.date) .collect::>(), - false, + common::DefaultInterval::_3M, ); let exercise = &data_model.exercises.get(&model.exercise_id); diff --git a/frontend/src/page/menstrual_cycle.rs b/frontend/src/page/menstrual_cycle.rs index 3c1c99f..bd53666 100644 --- a/frontend/src/page/menstrual_cycle.rs +++ b/frontend/src/page/menstrual_cycle.rs @@ -29,7 +29,7 @@ pub fn init( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ), dialog: Dialog::Hidden, loading: false, @@ -185,7 +185,7 @@ pub fn update( .keys() .copied() .collect::>(), - false, + common::DefaultInterval::_3M, ); } data::Event::PeriodCreatedOk diff --git a/frontend/src/page/muscles.rs b/frontend/src/page/muscles.rs index 94b36e1..7b944f4 100644 --- a/frontend/src/page/muscles.rs +++ b/frontend/src/page/muscles.rs @@ -19,7 +19,7 @@ pub fn init(data_model: &data::Model, navbar: &mut crate::Navbar) -> Model { .values() .map(|t| t.date) .collect::>(), - false, + common::DefaultInterval::_1M, ), } } diff --git a/frontend/src/page/routine.rs b/frontend/src/page/routine.rs index 6c88c5c..45e974c 100644 --- a/frontend/src/page/routine.rs +++ b/frontend/src/page/routine.rs @@ -30,7 +30,7 @@ pub fn init( navbar.title = String::from("Routine"); let mut model = Model { - interval: common::init_interval(&[], true), + interval: common::init_interval(&[], common::DefaultInterval::All), routine_id, name: common::InputField::default(), sections: vec![], @@ -679,7 +679,7 @@ fn update_model(model: &mut Model, data_model: &data::Model) { .filter(|t| t.routine_id == Some(model.routine_id)) .map(|t| t.date) .collect::>(), - true, + common::DefaultInterval::All, ); let routine = &data_model.routines.get(&model.routine_id); diff --git a/frontend/src/page/training.rs b/frontend/src/page/training.rs index c4c770a..2d8ee0e 100644 --- a/frontend/src/page/training.rs +++ b/frontend/src/page/training.rs @@ -31,7 +31,7 @@ pub fn init( .values() .map(|t| t.date) .collect::>(), - false, + common::DefaultInterval::_1M, ), dialog: Dialog::Hidden, loading: false, @@ -182,7 +182,7 @@ pub fn update( .values() .map(|t| t.date) .collect::>(), - false, + common::DefaultInterval::_1M, ); } data::Event::TrainingSessionCreatedOk => {