From 76f4b314660e45fc5664da45c18c62ba9142398f Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 28 Jan 2024 16:28:27 -0500 Subject: [PATCH] Show existing time/distance workout rows in day detail and editor --- fitnesstrax/app/gresources.xml | 4 +++ .../app/resources/cycling-symbolic.svg | 2 ++ .../app/resources/resources.gresource.xml | 6 ---- fitnesstrax/app/src/components/day.rs | 35 +++++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 fitnesstrax/app/resources/cycling-symbolic.svg delete mode 100644 fitnesstrax/app/resources/resources.gresource.xml diff --git a/fitnesstrax/app/gresources.xml b/fitnesstrax/app/gresources.xml index 4eafed7..b26eb63 100644 --- a/fitnesstrax/app/gresources.xml +++ b/fitnesstrax/app/gresources.xml @@ -10,4 +10,8 @@ running-symbolic.svg + + + cycling-symbolic.svg + diff --git a/fitnesstrax/app/resources/cycling-symbolic.svg b/fitnesstrax/app/resources/cycling-symbolic.svg new file mode 100644 index 0000000..d1a3f13 --- /dev/null +++ b/fitnesstrax/app/resources/cycling-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/fitnesstrax/app/resources/resources.gresource.xml b/fitnesstrax/app/resources/resources.gresource.xml deleted file mode 100644 index 67e604b..0000000 --- a/fitnesstrax/app/resources/resources.gresource.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - start-here-symbolic.svg - - \ No newline at end of file diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs index ede6968..575e733 100644 --- a/fitnesstrax/app/src/components/day.rs +++ b/fitnesstrax/app/src/components/day.rs @@ -243,6 +243,23 @@ impl DayEdit { move |workout| s.add_row(workout) }); + view_model + .records() + .into_iter() + .filter_map({ + let s = s.clone(); + move |record| match record.data { + TraxRecord::TimeDistance(workout) => Some(TimeDistanceEdit::new(workout, { + let s = s.clone(); + move |data| { + s.update_workout(record.id, data); + } + })), + _ => None, + } + }) + .for_each(|row| s.imp().workout_rows.borrow().append(&row)); + s.append(&control_buttons(&s, &view_model)); s.append(&weight_and_steps_row(&view_model)); s.append(&*s.imp().workout_rows.borrow()); @@ -343,6 +360,7 @@ where AddRow: Fn(Record) + 'static, { let add_row = Rc::new(add_row); + /* let walking_button = gtk::Button::builder() .icon_name("walking2-symbolic") .width_request(64) @@ -369,6 +387,20 @@ where add_row(workout.map(TraxRecord::TimeDistance)); } }); + */ + + let biking_button = gtk::Button::builder() + .icon_name("cycling-symbolic") + .width_request(64) + .height_request(64) + .build(); + biking_button.connect_clicked({ + let view_model = view_model.clone(); + move |_| { + let workout = view_model.new_time_distance(TimeDistanceActivity::Walking); + add_row(workout.map(TraxRecord::TimeDistance)); + } + }); let layout = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) @@ -376,8 +408,7 @@ where let row = gtk::Box::builder() .orientation(gtk::Orientation::Horizontal) .build(); - row.append(&walking_button); - row.append(&running_button); + row.append(&biking_button); layout.append(&row); layout