mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-23 19:49:58 -04:00
cargo fmt
This commit is contained in:
parent
bb092212ac
commit
874a5fdb57
@ -2,4 +2,4 @@
|
||||
fn main() {
|
||||
// trigger recompilation when a new migration is added
|
||||
println!("cargo:rerun-if-changed=migrations");
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
|
@ -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!(),
|
||||
|
@ -400,7 +400,7 @@ pub fn measure(i: StrIter) -> abortable_parser::Result<StrIter, Measure> {
|
||||
"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!()
|
||||
|
@ -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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<S: AsRef<str> + serde::Serialize>(&self, content: S) -> Result<(), Error> {
|
||||
pub async fn store_staples<S: AsRef<str> + 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)
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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<G> {
|
||||
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" }
|
||||
|
@ -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<V, E> {
|
||||
|
@ -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;
|
||||
|
@ -24,7 +24,10 @@ pub struct LinearSignal<'ctx, Payload> {
|
||||
|
||||
impl<'ctx, Payload> Into<LinearSignal<'ctx, Payload>> for &'ctx Signal<Payload> {
|
||||
fn into(self) -> LinearSignal<'ctx, Payload> {
|
||||
LinearSignal { signal: self, nv: None }
|
||||
LinearSignal {
|
||||
signal: self,
|
||||
nv: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
Loading…
x
Reference in New Issue
Block a user