From ddb72d71d40d585d42e4cad862b8eafcbf0cd619 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 27 Dec 2023 17:14:47 -0500 Subject: [PATCH] Switch to an the updated emseries record type --- fitnesstrax/app/src/app.rs | 29 ++++++++++++++++++++++++++- fitnesstrax/app/src/components/day.rs | 4 ++-- fitnesstrax/core/src/lib.rs | 4 +--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/fitnesstrax/app/src/app.rs b/fitnesstrax/app/src/app.rs index 8482fd1..49500d6 100644 --- a/fitnesstrax/app/src/app.rs +++ b/fitnesstrax/app/src/app.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 emseries::Series; +use emseries::{Record, RecordId, Series}; use ft_core::TraxRecord; use std::{ path::{Path, PathBuf}, @@ -30,6 +30,12 @@ pub enum AppInvocation { /// Request a set of records from the core. // Note: this will require a time range, but doesn't yet. RequestRecords, + + UpdateRecord(Record), + + PutRecord(TraxRecord), + + DeleteRecord(RecordId), } /// Responses are messages that the core sends to the UI. Though they are called responses, the @@ -83,6 +89,27 @@ impl App { AppResponse::Records } } + AppInvocation::UpdateRecord(record) => match *self.database.write().unwrap() { + Some(ref mut database) => { + database.update(record).unwrap(); + AppResponse::Records + } + None => AppResponse::NoDatabase, + }, + AppInvocation::PutRecord(record) => match *self.database.write().unwrap() { + Some(ref mut database) => { + database.put(record).unwrap(); + AppResponse::Records + } + None => AppResponse::NoDatabase, + }, + AppInvocation::DeleteRecord(record_id) => match *self.database.write().unwrap() { + Some(ref mut database) => { + database.delete(&record_id).unwrap(); + AppResponse::Records + } + None => AppResponse::NoDatabase, + }, } } diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs index f6f8b98..690d9d3 100644 --- a/fitnesstrax/app/src/components/day.rs +++ b/fitnesstrax/app/src/components/day.rs @@ -157,10 +157,10 @@ impl DayDetail { }); let weight_view = match weight_record { - Some((unique_id, record)) => WeightView::new(Some(record), move |weight| { + Some((id, record)) => WeightView::new(Some(record.clone()), move |weight| { println!( "on_blur on the weight view. Need to record {:?}, {:?}", - unique_id, weight + id, weight ); }), None => WeightView::new(None, |weight| { diff --git a/fitnesstrax/core/src/lib.rs b/fitnesstrax/core/src/lib.rs index 6b89018..207f483 100644 --- a/fitnesstrax/core/src/lib.rs +++ b/fitnesstrax/core/src/lib.rs @@ -1,6 +1,4 @@ -use chrono::NaiveDate; -use dimensioned::si; - mod legacy; + mod types; pub use types::{RecordType, Steps, TimeDistance, TraxRecord, Weight};