mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-25 20:09:48 -04:00
cargo fmt
This commit is contained in:
parent
bb092212ac
commit
874a5fdb57
@ -2,4 +2,4 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
// trigger recompilation when a new migration is added
|
// trigger recompilation when a new migration is added
|
||||||
println!("cargo:rerun-if-changed=migrations");
|
println!("cargo:rerun-if-changed=migrations");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use std::collections::BTreeMap;
|
|
||||||
// Copyright 2022 Jeremy Wall
|
// Copyright 2022 Jeremy Wall
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// 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.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{collections::BTreeSet, net::SocketAddr};
|
use std::{collections::BTreeSet, net::SocketAddr};
|
||||||
|
@ -164,7 +164,10 @@ impl IngredientAccumulator {
|
|||||||
if lnm == rnm {
|
if lnm == rnm {
|
||||||
vec![Package(lnm.clone(), lqty + rqty)]
|
vec![Package(lnm.clone(), lqty + rqty)]
|
||||||
} else {
|
} else {
|
||||||
vec![Package(lnm.clone(), lqty.clone()), Package(rnm.clone(), rqty.clone())]
|
vec![
|
||||||
|
Package(lnm.clone(), lqty.clone()),
|
||||||
|
Package(rnm.clone(), rqty.clone()),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -400,7 +400,7 @@ pub fn measure(i: StrIter) -> abortable_parser::Result<StrIter, Measure> {
|
|||||||
"oz" => Weight(Oz(qty)),
|
"oz" => Weight(Oz(qty)),
|
||||||
"kg" | "kilogram" => Weight(Kilogram(qty)),
|
"kg" | "kilogram" => Weight(Kilogram(qty)),
|
||||||
"g" | "gram" => Weight(Gram(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 => {
|
_u => {
|
||||||
eprintln!("Invalid unit: {}", _u);
|
eprintln!("Invalid unit: {}", _u);
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
@ -21,7 +21,8 @@ use std::{
|
|||||||
cmp::{Ordering, PartialEq, PartialOrd},
|
cmp::{Ordering, PartialEq, PartialOrd},
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
ops::{Add, Div, Mul, Sub}, rc::Rc,
|
ops::{Add, Div, Mul, Sub},
|
||||||
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use num_rational::Ratio;
|
use num_rational::Ratio;
|
||||||
@ -320,7 +321,7 @@ macro_rules! weight_op {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $trait for WeightMeasure {
|
impl $trait for WeightMeasure {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
@ -375,7 +376,7 @@ pub enum Measure {
|
|||||||
Weight(WeightMeasure),
|
Weight(WeightMeasure),
|
||||||
}
|
}
|
||||||
|
|
||||||
use Measure::{Count, Volume, Weight, Package};
|
use Measure::{Count, Package, Volume, Weight};
|
||||||
|
|
||||||
impl Measure {
|
impl Measure {
|
||||||
pub fn tsp(qty: Quantity) -> Self {
|
pub fn tsp(qty: Quantity) -> Self {
|
||||||
@ -580,8 +581,12 @@ macro_rules! quantity_op {
|
|||||||
Ratio::from_integer(*lhs),
|
Ratio::from_integer(*lhs),
|
||||||
)),
|
)),
|
||||||
(Frac(rhs), Frac(lhs)) => Frac($trait::$method(rhs, lhs)),
|
(Frac(rhs), Frac(lhs)) => Frac($trait::$method(rhs, lhs)),
|
||||||
(Whole(rhs), Frac(lhs)) => Frac($trait::$method(Ratio::from_integer(*rhs), lhs)),
|
(Whole(rhs), Frac(lhs)) => {
|
||||||
(Frac(rhs), Whole(lhs)) => Frac($trait::$method(rhs, Ratio::from_integer(*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 wasm_bindgen::JsValue;
|
||||||
use web_sys::Storage;
|
use web_sys::Storage;
|
||||||
|
|
||||||
use crate::{app_state::{AppState, parse_recipes}, js_lib};
|
use crate::{
|
||||||
|
app_state::{parse_recipes, AppState},
|
||||||
|
js_lib,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Error(String);
|
pub struct Error(String);
|
||||||
@ -111,7 +114,8 @@ impl LocalStore {
|
|||||||
self.store.get("app_state").map_or(None, |val| {
|
self.store.get("app_state").map_or(None, |val| {
|
||||||
val.map(|s| {
|
val.map(|s| {
|
||||||
debug!("Found an app_state object");
|
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");
|
let recipes = parse_recipes(&self.get_recipes()).expect("Failed to parse recipes");
|
||||||
if let Some(recipes) = recipes {
|
if let Some(recipes) = recipes {
|
||||||
debug!("Populating recipes");
|
debug!("Populating recipes");
|
||||||
@ -160,12 +164,12 @@ impl LocalStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn migrate_local_store(&self) {
|
fn migrate_local_store(&self) {
|
||||||
for k in self.get_storage_keys()
|
for k in self.get_storage_keys().into_iter().filter(|k| {
|
||||||
.into_iter()
|
k.starts_with("categor") || k == "inventory" || k.starts_with("plan") || k == "staples"
|
||||||
.filter(|k| k.starts_with("categor") || k == "inventory" || k.starts_with("plan") || k == "staples") {
|
}) {
|
||||||
// Deleting old local store key
|
// Deleting old local store key
|
||||||
debug!("Deleting old local store key {}", k);
|
debug!("Deleting old local store key {}", k);
|
||||||
self.store.delete(&k).expect("Failed to delete storage key");
|
self.store.delete(&k).expect("Failed to delete storage key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,9 +284,10 @@ impl HttpStore {
|
|||||||
)
|
)
|
||||||
.mode(web_sys::RequestMode::SameOrigin)
|
.mode(web_sys::RequestMode::SameOrigin)
|
||||||
.credentials(web_sys::RequestCredentials::SameOrigin)
|
.credentials(web_sys::RequestCredentials::SameOrigin)
|
||||||
.build().expect("Failed to build request");
|
.build()
|
||||||
debug!(?request, "Sending auth request");
|
.expect("Failed to build request");
|
||||||
let result = request.send().await;
|
debug!(?request, "Sending auth request");
|
||||||
|
let result = request.send().await;
|
||||||
if let Ok(resp) = &result {
|
if let Ok(resp) = &result {
|
||||||
if resp.status() == 200 {
|
if resp.status() == 200 {
|
||||||
let user_data = resp
|
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();
|
let mut path = self.v2_path();
|
||||||
path.push_str("/staples");
|
path.push_str("/staples");
|
||||||
let resp = gloo_net::http::Request::post(&path)
|
let resp = gloo_net::http::Request::post(&path)
|
||||||
|
@ -16,7 +16,7 @@ use sycamore::prelude::*;
|
|||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
use wasm_web_component::{web_component, WebComponentBinding};
|
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;
|
use crate::js_lib::LogFailures;
|
||||||
|
|
||||||
@ -153,7 +153,12 @@ impl WebComponentBinding for NumberSpinner {
|
|||||||
) {
|
) {
|
||||||
let nval_el = self.get_input_el();
|
let nval_el = self.get_input_el();
|
||||||
let name = name.as_string().unwrap();
|
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() {
|
match name.as_str() {
|
||||||
"val" => {
|
"val" => {
|
||||||
debug!("COUNTS: got an updated value");
|
debug!("COUNTS: got an updated value");
|
||||||
@ -236,9 +241,15 @@ where
|
|||||||
create_effect(cx, move || {
|
create_effect(cx, move || {
|
||||||
let new_count = *counter.get();
|
let new_count = *counter.get();
|
||||||
debug!(new_count, "COUNTS: Updating spinner with new value");
|
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");
|
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();
|
let id = name.clone();
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use sycamore::prelude::*;
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
use crate::app_state::{Message, StateHandler};
|
use crate::app_state::{Message, StateHandler};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
@ -194,9 +194,7 @@ fn make_shopping_table<'ctx, G: Html>(
|
|||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
||||||
let show_staples = sh.get_selector(cx, |state| {
|
let show_staples = sh.get_selector(cx, |state| state.get().use_staples);
|
||||||
state.get().use_staples
|
|
||||||
});
|
|
||||||
view! {cx,
|
view! {cx,
|
||||||
h1 { "Shopping List " }
|
h1 { "Shopping List " }
|
||||||
label(for="show_staples_cb") { "Show staples" }
|
label(for="show_staples_cb") { "Show staples" }
|
||||||
|
@ -16,7 +16,8 @@ use tracing::error;
|
|||||||
use web_sys::{window, Storage, Window};
|
use web_sys::{window, Storage, Window};
|
||||||
|
|
||||||
pub fn get_storage() -> Storage {
|
pub fn get_storage() -> Storage {
|
||||||
get_window().local_storage()
|
get_window()
|
||||||
|
.local_storage()
|
||||||
.expect("Failed to get storage")
|
.expect("Failed to get storage")
|
||||||
.expect("No storage available")
|
.expect("No storage available")
|
||||||
}
|
}
|
||||||
@ -26,8 +27,7 @@ pub fn get_ms_timestamp() -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_window() -> Window {
|
pub fn get_window() -> Window {
|
||||||
window()
|
window().expect("No window present")
|
||||||
.expect("No window present")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LogFailures<V, E> {
|
pub trait LogFailures<V, E> {
|
||||||
|
@ -15,10 +15,10 @@ mod api;
|
|||||||
mod app_state;
|
mod app_state;
|
||||||
mod components;
|
mod components;
|
||||||
mod js_lib;
|
mod js_lib;
|
||||||
|
mod linear;
|
||||||
mod pages;
|
mod pages;
|
||||||
mod routing;
|
mod routing;
|
||||||
mod web;
|
mod web;
|
||||||
mod linear;
|
|
||||||
|
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
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> {
|
impl<'ctx, Payload> Into<LinearSignal<'ctx, Payload>> for &'ctx Signal<Payload> {
|
||||||
fn into(self) -> LinearSignal<'ctx, 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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use sycamore::{futures::spawn_local_scoped, prelude::*};
|
use sycamore::{futures::spawn_local_scoped, prelude::*};
|
||||||
use tracing::{info, debug, instrument};
|
use tracing::{debug, info, instrument};
|
||||||
|
|
||||||
use crate::app_state::Message;
|
use crate::app_state::Message;
|
||||||
use crate::{api, routing::Handler as RouteHandler};
|
use crate::{api, routing::Handler as RouteHandler};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user