diff --git a/kitchen/build.rs b/kitchen/build.rs index 7609593..d506869 100644 --- a/kitchen/build.rs +++ b/kitchen/build.rs @@ -2,4 +2,4 @@ fn main() { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); -} \ No newline at end of file +} diff --git a/kitchen/src/web/mod.rs b/kitchen/src/web/mod.rs index 09d1b03..c0ec8d0 100644 --- a/kitchen/src/web/mod.rs +++ b/kitchen/src/web/mod.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeMap; // Copyright 2022 Jeremy Wall // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +11,7 @@ use std::collections::BTreeMap; // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +use std::collections::BTreeMap; use std::path::PathBuf; use std::sync::Arc; use std::{collections::BTreeSet, net::SocketAddr}; diff --git a/recipes/src/lib.rs b/recipes/src/lib.rs index 53d40a7..c1e9aed 100644 --- a/recipes/src/lib.rs +++ b/recipes/src/lib.rs @@ -164,7 +164,10 @@ impl IngredientAccumulator { if lnm == rnm { vec![Package(lnm.clone(), lqty + rqty)] } else { - vec![Package(lnm.clone(), lqty.clone()), Package(rnm.clone(), rqty.clone())] + vec![ + Package(lnm.clone(), lqty.clone()), + Package(rnm.clone(), rqty.clone()), + ] } } _ => unreachable!(), diff --git a/recipes/src/parse.rs b/recipes/src/parse.rs index 987b287..9ee2714 100644 --- a/recipes/src/parse.rs +++ b/recipes/src/parse.rs @@ -400,7 +400,7 @@ pub fn measure(i: StrIter) -> abortable_parser::Result { "oz" => Weight(Oz(qty)), "kg" | "kilogram" => Weight(Kilogram(qty)), "g" | "gram" => Weight(Gram(qty)), - "pkg" | "package" | "can" | "bag" | "bottle" | "bot" => Measure::pkg(s, qty), + "pkg" | "package" | "can" | "bag" | "bottle" | "bot" => Measure::pkg(s, qty), _u => { eprintln!("Invalid unit: {}", _u); unreachable!() diff --git a/recipes/src/unit.rs b/recipes/src/unit.rs index 2ba223d..ea60379 100644 --- a/recipes/src/unit.rs +++ b/recipes/src/unit.rs @@ -21,7 +21,8 @@ use std::{ cmp::{Ordering, PartialEq, PartialOrd}, convert::TryFrom, fmt::Display, - ops::{Add, Div, Mul, Sub}, rc::Rc, + ops::{Add, Div, Mul, Sub}, + rc::Rc, }; use num_rational::Ratio; @@ -320,7 +321,7 @@ macro_rules! weight_op { } } } - + impl $trait for WeightMeasure { type Output = Self; @@ -375,7 +376,7 @@ pub enum Measure { Weight(WeightMeasure), } -use Measure::{Count, Volume, Weight, Package}; +use Measure::{Count, Package, Volume, Weight}; impl Measure { pub fn tsp(qty: Quantity) -> Self { @@ -580,8 +581,12 @@ macro_rules! quantity_op { Ratio::from_integer(*lhs), )), (Frac(rhs), Frac(lhs)) => Frac($trait::$method(rhs, lhs)), - (Whole(rhs), Frac(lhs)) => Frac($trait::$method(Ratio::from_integer(*rhs), lhs)), - (Frac(rhs), Whole(lhs)) => Frac($trait::$method(rhs, Ratio::from_integer(*lhs))), + (Whole(rhs), Frac(lhs)) => { + Frac($trait::$method(Ratio::from_integer(*rhs), lhs)) + } + (Frac(rhs), Whole(lhs)) => { + Frac($trait::$method(rhs, Ratio::from_integer(*lhs))) + } } } } diff --git a/web/src/api.rs b/web/src/api.rs index 5badbdc..dc6fe36 100644 --- a/web/src/api.rs +++ b/web/src/api.rs @@ -25,7 +25,10 @@ use recipes::{IngredientKey, RecipeEntry}; use wasm_bindgen::JsValue; use web_sys::Storage; -use crate::{app_state::{AppState, parse_recipes}, js_lib}; +use crate::{ + app_state::{parse_recipes, AppState}, + js_lib, +}; #[derive(Debug)] pub struct Error(String); @@ -111,7 +114,8 @@ impl LocalStore { self.store.get("app_state").map_or(None, |val| { val.map(|s| { debug!("Found an app_state object"); - let mut app_state: AppState = from_str(&s).expect("Failed to deserialize app state"); + let mut app_state: AppState = + from_str(&s).expect("Failed to deserialize app state"); let recipes = parse_recipes(&self.get_recipes()).expect("Failed to parse recipes"); if let Some(recipes) = recipes { debug!("Populating recipes"); @@ -160,12 +164,12 @@ impl LocalStore { } fn migrate_local_store(&self) { - for k in self.get_storage_keys() - .into_iter() - .filter(|k| k.starts_with("categor") || k == "inventory" || k.starts_with("plan") || k == "staples") { - // Deleting old local store key - debug!("Deleting old local store key {}", k); - self.store.delete(&k).expect("Failed to delete storage key"); + for k in self.get_storage_keys().into_iter().filter(|k| { + k.starts_with("categor") || k == "inventory" || k.starts_with("plan") || k == "staples" + }) { + // Deleting old local store key + debug!("Deleting old local store key {}", k); + self.store.delete(&k).expect("Failed to delete storage key"); } } @@ -280,9 +284,10 @@ impl HttpStore { ) .mode(web_sys::RequestMode::SameOrigin) .credentials(web_sys::RequestCredentials::SameOrigin) - .build().expect("Failed to build request"); - debug!(?request, "Sending auth request"); - let result = request.send().await; + .build() + .expect("Failed to build request"); + debug!(?request, "Sending auth request"); + let result = request.send().await; if let Ok(resp) = &result { if resp.status() == 200 { let user_data = resp @@ -762,7 +767,10 @@ impl HttpStore { } } - pub async fn store_staples + serde::Serialize>(&self, content: S) -> Result<(), Error> { + pub async fn store_staples + serde::Serialize>( + &self, + content: S, + ) -> Result<(), Error> { let mut path = self.v2_path(); path.push_str("/staples"); let resp = gloo_net::http::Request::post(&path) diff --git a/web/src/components/number_field.rs b/web/src/components/number_field.rs index 92b07b8..0486afa 100644 --- a/web/src/components/number_field.rs +++ b/web/src/components/number_field.rs @@ -16,7 +16,7 @@ use sycamore::prelude::*; use tracing::{debug, error}; use wasm_bindgen::JsCast; use wasm_web_component::{web_component, WebComponentBinding}; -use web_sys::{CustomEvent, Event, HtmlElement, InputEvent, ShadowRoot, window}; +use web_sys::{window, CustomEvent, Event, HtmlElement, InputEvent, ShadowRoot}; use crate::js_lib::LogFailures; @@ -153,7 +153,12 @@ impl WebComponentBinding for NumberSpinner { ) { let nval_el = self.get_input_el(); let name = name.as_string().unwrap(); - debug!(?name, ?old_value, ?new_value, "COUNTS: handling attribute change"); + debug!( + ?name, + ?old_value, + ?new_value, + "COUNTS: handling attribute change" + ); match name.as_str() { "val" => { debug!("COUNTS: got an updated value"); @@ -236,9 +241,15 @@ where create_effect(cx, move || { let new_count = *counter.get(); debug!(new_count, "COUNTS: Updating spinner with new value"); - if let Some(el) = window().unwrap().document().unwrap().get_element_by_id(id.as_str()) { + if let Some(el) = window() + .unwrap() + .document() + .unwrap() + .get_element_by_id(id.as_str()) + { debug!("COUNTS: found element"); - el.set_attribute("val", new_count.to_string().as_str()).unwrap(); + el.set_attribute("val", new_count.to_string().as_str()) + .unwrap(); } }); let id = name.clone(); diff --git a/web/src/components/plan_list.rs b/web/src/components/plan_list.rs index a083cbc..0a6060c 100644 --- a/web/src/components/plan_list.rs +++ b/web/src/components/plan_list.rs @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use sycamore::prelude::*; use chrono::NaiveDate; +use sycamore::prelude::*; use crate::app_state::{Message, StateHandler}; use tracing::instrument; diff --git a/web/src/components/shopping_list.rs b/web/src/components/shopping_list.rs index b0ea1e8..4248a80 100644 --- a/web/src/components/shopping_list.rs +++ b/web/src/components/shopping_list.rs @@ -194,9 +194,7 @@ fn make_shopping_table<'ctx, G: Html>( #[instrument(skip_all)] #[component] pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View { - let show_staples = sh.get_selector(cx, |state| { - state.get().use_staples - }); + let show_staples = sh.get_selector(cx, |state| state.get().use_staples); view! {cx, h1 { "Shopping List " } label(for="show_staples_cb") { "Show staples" } diff --git a/web/src/js_lib.rs b/web/src/js_lib.rs index 6acf37a..82596f5 100644 --- a/web/src/js_lib.rs +++ b/web/src/js_lib.rs @@ -16,7 +16,8 @@ use tracing::error; use web_sys::{window, Storage, Window}; pub fn get_storage() -> Storage { - get_window().local_storage() + get_window() + .local_storage() .expect("Failed to get storage") .expect("No storage available") } @@ -26,8 +27,7 @@ pub fn get_ms_timestamp() -> u32 { } pub fn get_window() -> Window { - window() - .expect("No window present") + window().expect("No window present") } pub trait LogFailures { diff --git a/web/src/lib.rs b/web/src/lib.rs index af53b8d..188d5c5 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -15,10 +15,10 @@ mod api; mod app_state; mod components; mod js_lib; +mod linear; mod pages; mod routing; mod web; -mod linear; use sycamore::prelude::*; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/web/src/linear.rs b/web/src/linear.rs index 80c16d9..355910b 100644 --- a/web/src/linear.rs +++ b/web/src/linear.rs @@ -24,7 +24,10 @@ pub struct LinearSignal<'ctx, Payload> { impl<'ctx, Payload> Into> for &'ctx Signal { fn into(self) -> LinearSignal<'ctx, Payload> { - LinearSignal { signal: self, nv: None } + LinearSignal { + signal: self, + nv: None, + } } } diff --git a/web/src/web.rs b/web/src/web.rs index c2b6883..bd40dc7 100644 --- a/web/src/web.rs +++ b/web/src/web.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. use sycamore::{futures::spawn_local_scoped, prelude::*}; -use tracing::{info, debug, instrument}; +use tracing::{debug, info, instrument}; use crate::app_state::Message; use crate::{api, routing::Handler as RouteHandler};