Lotsa Leptos

This commit is contained in:
Bianca Fürstenau 2025-02-22 16:00:00 +01:00
parent 49a9810fd8
commit 8a25a5fa82
5 changed files with 115 additions and 19 deletions

View file

@ -5,31 +5,105 @@ use leptos::task::spawn_local;
use bkbh_lib::types::*;
#[component]
fn SwapButton(store: Store, img_path: &'static str, pretty: &'static str) -> impl IntoView {
fn StoreLogo(store: Store) -> impl IntoView {
view! {
<img
src=format!("assets/{}.svg", Into::<String>::into(&store))
class="logo"
// FIXME: Implement fmt trait for Store
alt=format!("{:?}", store)
/>
}
}
#[component]
fn SwapButton(store: Store) -> impl IntoView {
view! {
<button
on:click=move |_| {
spawn_local(async {
swap("aldi", 0).await.unwrap();
})
spawn_local(async move {
swap(store, 0).await.unwrap();
});
}
class="column"
>
<img
src="assets/aldi.svg"
class="logo"
alt="ALDI-Süd"
/>
<StoreLogo store=store />
</button>
}
}
#[component]
fn StoreInput(store: Store) -> impl IntoView {
let txt = format!("{}", Into::<String>::into(&store));
view! {
<div
class="labelled-input"
>
<label
for=txt.clone()
>
<StoreLogo store=store />
</label>
<input
type="number"
name=txt.clone()
id=txt.clone()
min=0
/>
</div>
}
}
#[component]
fn AccRadio(acc: Account) -> impl IntoView {
let txt = format!("{}", Into::<String>::into(&acc));
let id = format!("acc-{}", txt);
view! {
<div
class="labelled-input"
>
<input
type="radio"
name="acc"
id=id.clone()
value=txt
required
/>
<label
for=id.clone()
>
// FIXME: Implement fmt trait for Account
{format!("{:?}", acc)}
</label>
</div>
}
}
#[component]
fn InvForm() -> impl IntoView {
view! {
<form>
<AccRadio acc=Account::Sumpf />
<AccRadio acc=Account::Heinersyndikat />
<StoreInput store=Store::Aldi />
<StoreInput store=Store::Dm />
<StoreInput store=Store::Lidl />
<StoreInput store=Store::Rewe />
<StoreInput store=Store::Tegut />
</form>
}
}
fn main() {
console_error_panic_hook::set_once();
leptos::mount::mount_to_body(|| view! {
<SwapButton
store=Store::Aldi
img_path=&"aldi"
pretty=&"Aldi"
/>
<div
id="cafe-inventory"
>
<InvForm />
</div>
});
}