Add the ability to edit the time of a workout and the associated activity. #183

Merged
savanni merged 5 commits from fitnesstrax/edit-time-and-activity into main 2024-02-09 13:31:40 +00:00
4 changed files with 15 additions and 15 deletions
Showing only changes of commit 73a5ab89a3 - Show all commits

View File

@ -386,7 +386,7 @@ where
biking_button.connect_clicked({ biking_button.connect_clicked({
let view_model = view_model.clone(); let view_model = view_model.clone();
move |_| { move |_| {
let workout = view_model.new_time_distance(TimeDistanceActivity::BikeRide); let workout = view_model.new_time_distance(TimeDistanceActivity::Biking);
add_row(workout.map(TraxRecord::TimeDistance)); add_row(workout.map(TraxRecord::TimeDistance));
} }
}); });

View File

@ -129,7 +129,7 @@ impl Default for TimeDistanceEditPrivate {
Self { Self {
workout: RefCell::new(TimeDistance { workout: RefCell::new(TimeDistance {
datetime: chrono::Utc::now().into(), datetime: chrono::Utc::now().into(),
activity: TimeDistanceActivity::BikeRide, activity: TimeDistanceActivity::Biking,
duration: None, duration: None,
distance: None, distance: None,
comments: None, comments: None,

View File

@ -510,7 +510,7 @@ mod test {
id: RecordId::default(), id: RecordId::default(),
data: TraxRecord::TimeDistance(ft_core::TimeDistance { data: TraxRecord::TimeDistance(ft_core::TimeDistance {
datetime: oct_13_am.clone(), datetime: oct_13_am.clone(),
activity: TimeDistanceActivity::BikeRide, activity: TimeDistanceActivity::Biking,
distance: Some(15000. * si::M), distance: Some(15000. * si::M),
duration: Some(3600. * si::S), duration: Some(3600. * si::S),
comments: Some("somecomments present".to_owned()), comments: Some("somecomments present".to_owned()),
@ -560,11 +560,11 @@ mod test {
async fn it_can_construct_new_records() { async fn it_can_construct_new_records() {
let (view_model, provider) = create_empty_view_model().await; let (view_model, provider) = create_empty_view_model().await;
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(0. * si::M, 0. * si::S) (0. * si::M, 0. * si::S)
); );
let mut record = view_model.new_time_distance(TimeDistanceActivity::BikeRide); let mut record = view_model.new_time_distance(TimeDistanceActivity::Biking);
record.data.duration = Some(60. * si::S); record.data.duration = Some(60. * si::S);
view_model.async_save().await; view_model.async_save().await;
@ -577,17 +577,17 @@ mod test {
async fn it_can_update_a_new_record_before_saving() { async fn it_can_update_a_new_record_before_saving() {
let (view_model, provider) = create_empty_view_model().await; let (view_model, provider) = create_empty_view_model().await;
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(0. * si::M, 0. * si::S) (0. * si::M, 0. * si::S)
); );
let mut record = view_model.new_time_distance(TimeDistanceActivity::BikeRide); let mut record = view_model.new_time_distance(TimeDistanceActivity::Biking);
record.data.duration = Some(60. * si::S); record.data.duration = Some(60. * si::S);
let record = record.map(TraxRecord::TimeDistance); let record = record.map(TraxRecord::TimeDistance);
view_model.update_record(record.clone()); view_model.update_record(record.clone());
assert_eq!(view_model.get_record(&record.id), Some(record)); assert_eq!(view_model.get_record(&record.id), Some(record));
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(0. * si::M, 60. * si::S) (0. * si::M, 60. * si::S)
); );
assert_eq!( assert_eq!(
@ -610,7 +610,7 @@ mod test {
view_model.update_record(workout.map(TraxRecord::TimeDistance)); view_model.update_record(workout.map(TraxRecord::TimeDistance));
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(15000. * si::M, 1800. * si::S) (15000. * si::M, 1800. * si::S)
); );
@ -625,11 +625,11 @@ mod test {
async fn it_can_remove_a_new_record() { async fn it_can_remove_a_new_record() {
let (view_model, provider) = create_empty_view_model().await; let (view_model, provider) = create_empty_view_model().await;
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(0. * si::M, 0. * si::S) (0. * si::M, 0. * si::S)
); );
let record = view_model.new_time_distance(TimeDistanceActivity::BikeRide); let record = view_model.new_time_distance(TimeDistanceActivity::Biking);
view_model.remove_record(record.id); view_model.remove_record(record.id);
view_model.save(); view_model.save();
@ -645,7 +645,7 @@ mod test {
view_model.remove_record(workout.id); view_model.remove_record(workout.id);
assert_eq!( assert_eq!(
view_model.time_distance_summary(TimeDistanceActivity::BikeRide), view_model.time_distance_summary(TimeDistanceActivity::Biking),
(0. * si::M, 0. * si::S) (0. * si::M, 0. * si::S)
); );
view_model.async_save().await; view_model.async_save().await;

View File

@ -51,7 +51,7 @@ impl Recordable for Steps {
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum TimeDistanceActivity { pub enum TimeDistanceActivity {
BikeRide, Biking,
Running, Running,
Rowing, Rowing,
Swimming, Swimming,
@ -59,7 +59,7 @@ pub enum TimeDistanceActivity {
} }
pub const TIME_DISTANCE_ACTIVITIES: [TimeDistanceActivity; 5] = [ pub const TIME_DISTANCE_ACTIVITIES: [TimeDistanceActivity; 5] = [
TimeDistanceActivity::BikeRide, TimeDistanceActivity::Biking,
TimeDistanceActivity::Rowing, TimeDistanceActivity::Rowing,
TimeDistanceActivity::Running, TimeDistanceActivity::Running,
TimeDistanceActivity::Swimming, TimeDistanceActivity::Swimming,
@ -141,7 +141,7 @@ impl TraxRecord {
matches!( matches!(
self, self,
TraxRecord::TimeDistance(TimeDistance { TraxRecord::TimeDistance(TimeDistance {
activity: TimeDistanceActivity::BikeRide, activity: TimeDistanceActivity::Biking,
.. ..
}) | TraxRecord::TimeDistance(TimeDistance { }) | TraxRecord::TimeDistance(TimeDistance {
activity: TimeDistanceActivity::Running, activity: TimeDistanceActivity::Running,