Thoroughly fill out the day detail view model along with proper automated testing #179
|
@ -136,20 +136,19 @@ impl AppWindow {
|
|||
fn show_historical_view(&self, records: Vec<Record<TraxRecord>>) {
|
||||
let view = View::Historical(HistoricalView::new(self.app.clone(), records, {
|
||||
let s = self.clone();
|
||||
Rc::new(move |date, records| {
|
||||
Rc::new(move |date, _records| {
|
||||
let s = s.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||
layout.append(&adw::HeaderBar::new());
|
||||
// layout.append(&DayDetailView::new(date, records, s.app.clone()));
|
||||
layout.append(&DayDetailView::new(DayDetailViewModel::new(
|
||||
date,
|
||||
records,
|
||||
s.app.clone(),
|
||||
)));
|
||||
let view_model = DayDetailViewModel::new(date, s.app.clone()).await;
|
||||
layout.append(&DayDetailView::new(view_model));
|
||||
let page = &adw::NavigationPage::builder()
|
||||
.title(date.format("%Y-%m-%d").to_string())
|
||||
.child(&layout)
|
||||
.build();
|
||||
s.navigation.push(page);
|
||||
});
|
||||
})
|
||||
}));
|
||||
self.swap_main(view);
|
||||
|
|
|
@ -85,7 +85,9 @@ pub struct DayDetailViewModel {
|
|||
}
|
||||
|
||||
impl DayDetailViewModel {
|
||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>, app: App) -> Self {
|
||||
pub async fn new(date: chrono::NaiveDate, app: App) -> Self {
|
||||
let records = app.records(date, date).await.unwrap();
|
||||
|
||||
let (weight_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_weight());
|
||||
let (step_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
|
|
|
@ -59,6 +59,9 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
|||
factory.connect_bind({
|
||||
let app = s.app.clone();
|
||||
move |_, list_item| {
|
||||
let app = app.clone();
|
||||
let list_item = list_item.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let records = list_item
|
||||
.downcast_ref::<gtk::ListItem>()
|
||||
.expect("should be a ListItem")
|
||||
|
@ -74,12 +77,10 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
|||
.expect("should be a DaySummary");
|
||||
|
||||
if let Some(app) = app.borrow().clone() {
|
||||
summary.set_data(DayDetailViewModel::new(
|
||||
records.date(),
|
||||
records.records(),
|
||||
app.clone(),
|
||||
));
|
||||
let view_model = DayDetailViewModel::new(records.date(), app.clone()).await;
|
||||
summary.set_data(view_model);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue