From d70ca08db21d9743e2d3a3ad237ef8a61e33fc53 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 19 Feb 2024 16:47:10 -0500 Subject: [PATCH] Correctly set the date range picker when initializing the historical view --- fitnesstrax/app/src/components/date_range.rs | 4 ++-- fitnesstrax/app/src/views/historical_view.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fitnesstrax/app/src/components/date_range.rs b/fitnesstrax/app/src/components/date_range.rs index 6cb0198..8f014bd 100644 --- a/fitnesstrax/app/src/components/date_range.rs +++ b/fitnesstrax/app/src/components/date_range.rs @@ -65,12 +65,12 @@ impl DateRangePicker { *self.imp().on_search.borrow_mut() = Box::new(f); } - fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) { + pub fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) { self.imp().start.set_date(start); self.imp().end.set_date(end); } - fn interval(&self) -> DayInterval { + pub fn interval(&self) -> DayInterval { DayInterval { start: self.imp().start.date(), end: self.imp().end.date(), diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index 02848ee..ec7b384 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -30,6 +30,7 @@ use std::{cell::RefCell, rc::Rc}; pub struct HistoricalViewPrivate { app: Rc>>, list_view: gtk::ListView, + date_range_picker: DateRangePicker, } #[glib::object_subclass] @@ -47,12 +48,15 @@ impl ObjectSubclass for HistoricalViewPrivate { .set_child(Some(&DaySummary::new())); }); + let date_range_picker = DateRangePicker::default(); + let s = Self { app: Rc::new(RefCell::new(None)), list_view: gtk::ListView::builder() .factory(&factory) .single_click_activate(true) .build(), + date_range_picker, }; factory.connect_bind({ @@ -106,17 +110,11 @@ impl HistoricalView { *s.imp().app.borrow_mut() = Some(app); - let date_range_picker = DateRangePicker::default(); - date_range_picker.connect_on_search({ + s.imp().date_range_picker.connect_on_search({ let s = s.clone(); move |interval| s.set_interval(interval) }); - - let mut model = gio::ListStore::new::(); - model.extend(interval.days().map(Date::new)); - s.imp() - .list_view - .set_model(Some(>k::NoSelection::new(Some(model)))); + s.set_interval(interval); s.imp().list_view.connect_activate({ let on_select_day = on_select_day.clone(); @@ -135,7 +133,7 @@ impl HistoricalView { .hscrollbar_policy(gtk::PolicyType::Never) .build(); - s.append(&date_range_picker); + s.append(&s.imp().date_range_picker); s.append(&scroller); s @@ -147,6 +145,7 @@ impl HistoricalView { self.imp() .list_view .set_model(Some(>k::NoSelection::new(Some(model)))); + self.imp().date_range_picker.set_interval(interval.start, interval.end); } }