This commit is contained in:
Bianca Fürstenau 2025-02-26 07:28:13 +01:00
parent 8a25a5fa82
commit 18814f18e0
5 changed files with 127 additions and 2 deletions

View file

@ -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<Self, Self::Err> {
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<String>) -> impl IntoView {
let txt = "cash";
view! {
<div
class="labelled-input"
>
<label
for=txt.clone()
>
<img
src="assets/cash.svg"
class="logo"
alt="Bargeld"
/>
</label>
<input
type="number"
name=txt.clone()
id=txt.clone()
min=0
step=0.01
bind:value=value
on:change=move |_| {
println!("{:?}", value.get());
}
/>
</div>
}
}
#[component]
fn AccRadio(acc: Account) -> impl IntoView {
let txt = format!("{}", Into::<String>::into(&acc));
@ -80,9 +135,28 @@ fn AccRadio(acc: Account) -> impl IntoView {
}
#[component]
fn InvForm() -> impl IntoView {
fn SubmitButton() -> impl IntoView {
view! {
<form>
<button
type="submit"
class="shout"
>
"Senden"
</button>
}
}
#[component]
fn InvForm() -> impl IntoView {
let cash = RwSignal::new(String::from("0.00"));
view! {
<form
on:submit=move |ev| {
ev.prevent_default();
let data = FromFormData::from_event(ev.as_ref()).unwrap();
spawn_local(async move {inventory(data).await;});
}
>
<AccRadio acc=Account::Sumpf />
<AccRadio acc=Account::Heinersyndikat />
<StoreInput store=Store::Aldi />
@ -90,6 +164,8 @@ fn InvForm() -> impl IntoView {
<StoreInput store=Store::Lidl />
<StoreInput store=Store::Rewe />
<StoreInput store=Store::Tegut />
<CashInput value=cash />
<SubmitButton />
</form>
}
}