diff --git a/fitnesstrax/app/src/app.rs b/fitnesstrax/app/src/app.rs index 54fcbeb..655b2c4 100644 --- a/fitnesstrax/app/src/app.rs +++ b/fitnesstrax/app/src/app.rs @@ -14,6 +14,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see . */ +use crate::types::DayInterval; use chrono::NaiveDate; use emseries::{time_range, Record, RecordId, Series, Timestamp}; use ft_core::TraxRecord; diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs index 6af77a1..8529c04 100644 --- a/fitnesstrax/app/src/components/day.rs +++ b/fitnesstrax/app/src/components/day.rs @@ -320,8 +320,10 @@ impl WeightView { } fn blur(&self) { - if *self.imp().current.borrow() == *self.imp().edit.borrow() { - self.imp().on_edit_finished.borrow()(0. * si::KG); + let edit = self.imp().edit.borrow(); + if *self.imp().current.borrow() == *edit { + let w = edit.buffer().text().parse::().unwrap(); + self.imp().on_edit_finished.borrow()(w * si::KG); self.view(); } } diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index 4ac8961..0811941 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -17,11 +17,13 @@ You should have received a copy of the GNU General Public License along with Fit mod app; mod app_window; mod components; +mod types; mod views; use adw::prelude::*; use app_window::AppWindow; use std::{env, path::PathBuf}; +use types::DayInterval; const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev"; const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax"; diff --git a/fitnesstrax/app/src/types.rs b/fitnesstrax/app/src/types.rs new file mode 100644 index 0000000..319e845 --- /dev/null +++ b/fitnesstrax/app/src/types.rs @@ -0,0 +1,47 @@ +use chrono::{Duration, Local, NaiveDate}; + +// This interval doesn't feel right, either. The idea that I have a specific interval type for just +// NaiveDate is odd. This should be genericized, as should the iterator. Also, it shouldn't live +// here, but in utilities. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct DayInterval { + pub start: NaiveDate, + pub end: NaiveDate, +} + +impl Default for DayInterval { + fn default() -> Self { + Self { + start: (Local::now() - Duration::days(7)).date_naive(), + end: Local::now().date_naive(), + } + } +} + +impl DayInterval { + pub fn days(&self) -> impl Iterator { + DayIterator { + current: self.start.clone(), + end: self.end.clone(), + } + } +} + +struct DayIterator { + current: NaiveDate, + end: NaiveDate, +} + +impl Iterator for DayIterator { + type Item = NaiveDate; + + fn next(&mut self) -> Option { + if self.current <= self.end { + let val = self.current.clone(); + self.current += Duration::days(1); + Some(val) + } else { + None + } + } +} diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index 938223d..ad68396 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -14,7 +14,7 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see . */ -use crate::components::DaySummary; +use crate::{components::DaySummary, types::DayInterval}; use chrono::{Duration, Local, NaiveDate}; use emseries::Record; use ft_core::TraxRecord; @@ -196,52 +196,6 @@ impl GroupedRecords { } } -// This interval doesn't feel right, either. The idea that I have a specific interval type for just -// NaiveDate is odd. This should be genericized, as should the iterator. Also, it shouldn't live -// here, but in utilities. -#[derive(Clone, Debug, PartialEq, Eq)] -struct DayInterval { - start: NaiveDate, - end: NaiveDate, -} - -impl Default for DayInterval { - fn default() -> Self { - Self { - start: (Local::now() - Duration::days(7)).date_naive(), - end: Local::now().date_naive(), - } - } -} - -impl DayInterval { - fn days(&self) -> impl Iterator { - DayIterator { - current: self.start.clone(), - end: self.end.clone(), - } - } -} - -struct DayIterator { - current: NaiveDate, - end: NaiveDate, -} - -impl Iterator for DayIterator { - type Item = NaiveDate; - - fn next(&mut self) -> Option { - if self.current <= self.end { - let val = self.current.clone(); - self.current += Duration::days(1); - Some(val) - } else { - None - } - } -} - #[cfg(test)] mod test { use super::GroupedRecords;