From 18814f18e01a1cab1a72cbd0a14e036d8273108c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bianca=20F=C3=BCrstenau?= Date: Wed, 26 Feb 2025 07:28:13 +0100 Subject: [PATCH] Add Cash --- Cargo.lock | 37 ++++++++++++++++++++++ Cargo.toml | 1 + src/bin/leptos.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++-- src/commands.rs | 10 ++++++ src/server/mod.rs | 1 + 5 files changed, 127 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df3aedb..87e1aa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,6 +353,7 @@ dependencies = [ "console_error_panic_hook", "curl", "leptos", + "leptos_router", "openssl", "rand 0.8.5", "ring-compat", @@ -2533,6 +2534,42 @@ dependencies = [ "uuid", ] +[[package]] +name = "leptos_router" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83cf6033f987f366be6ffa556ee22fa6f9f433cbffd173826fd67327c3ae7ed" +dependencies = [ + "any_spawner", + "either_of", + "futures", + "gloo-net", + "js-sys", + "leptos", + "leptos_router_macro", + "once_cell", + "or_poisoned", + "reactive_graph", + "send_wrapper", + "tachys", + "thiserror 2.0.11", + "url", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "leptos_router_macro" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f580227933b49028cd3b6d7cd29ab7c6d30f9777cf0ac774eda2aab000a912" +dependencies = [ + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "leptos_server" version = "0.7.7" diff --git a/Cargo.toml b/Cargo.toml index cceaad0..abaf228 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ tauri-build = { version = "2", features = [] } [dependencies] leptos = { version = "^0.7", features = ["csr"] } +leptos_router = { version = "^0.7" } tauri-sys = { path = "../tauri-sys", features = ["core"] } serde = { version = "1", features = ["derive"] } serde_json = { version = "1" } diff --git a/src/bin/leptos.rs b/src/bin/leptos.rs index 37200df..fbe40b0 100644 --- a/src/bin/leptos.rs +++ b/src/bin/leptos.rs @@ -1,6 +1,9 @@ use leptos::prelude::*; use bkbh_lib::commands::*; use leptos::task::spawn_local; +use leptos::web_sys::FormData; +use leptos::form::FromFormData; +use std::collections::HashMap; use bkbh_lib::types::*; @@ -54,6 +57,58 @@ fn StoreInput(store: Store) -> impl IntoView { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +struct Cash(i64); + +impl std::str::FromStr for Cash { + type Err = (); + + fn from_str(s: &str) -> Result { + let split: Vec<&str> = s.split(".").collect(); + let i = i64::from_str(split.get(0).ok_or(())?) + .map_err(|e| println!("{:?}", e))?; + let f = match split.get(1) { + None => 0, + Some(fs) => i64::from_str( + &format!("00{}", fs)[0..2] + ) + .map_err(|e| println!("{:?}", e))?, + }; + Ok(Cash(i*100+f)) + } +} + +#[component] +fn CashInput(value: RwSignal) -> impl IntoView { + let txt = "cash"; + view! { +
+ + +
+ } +} + #[component] fn AccRadio(acc: Account) -> impl IntoView { let txt = format!("{}", Into::::into(&acc)); @@ -80,9 +135,28 @@ fn AccRadio(acc: Account) -> impl IntoView { } #[component] -fn InvForm() -> impl IntoView { +fn SubmitButton() -> impl IntoView { view! { -
+ + } +} + +#[component] +fn InvForm() -> impl IntoView { + let cash = RwSignal::new(String::from("0.00")); + view! { + @@ -90,6 +164,8 @@ fn InvForm() -> impl IntoView { + + } } diff --git a/src/commands.rs b/src/commands.rs index ee27cf3..77f271c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,6 +1,7 @@ use tauri_sys::Error; use tauri_sys::core::invoke; use crate::types::*; +use std::collections::HashMap; #[derive(serde::Serialize)] pub struct Swap { @@ -11,3 +12,12 @@ pub async fn swap(store: Store, acc: i64) -> Result<(), Error> { let args = Swap { store, acc }; invoke("swap", &args).await } + +#[derive(serde::Serialize)] +pub struct Inventory { + data: HashMap, +} +pub async fn inventory(data: HashMap) -> Result<(), Error> { + let args = Inventory { data }; + invoke("inventory", &args).await +} diff --git a/src/server/mod.rs b/src/server/mod.rs index 56072e3..87cf516 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -40,6 +40,7 @@ pub async fn inventory( data: HashMap, state: State<'_, Mutex>, ) -> Result<(), ()> { + println!("{:?}", data); let now = Utc::now().timestamp(); let state = state.lock().await; let inv = parse_inventory(data)?;