More swap buttons again

This commit is contained in:
Bianca Fürstenau 2025-03-05 03:14:04 +01:00
parent 9e49770b99
commit 7cc7f03e5c
2 changed files with 67 additions and 28 deletions

View file

@ -8,14 +8,45 @@ use crate::types::*;
#[component]
pub fn Cafe() -> impl IntoView {
let acc = signal(Account::Sumpf);
view! {
<SwapButton
store=Store::Aldi
<Reception
acc=acc.0
/>
}
}
#[component]
fn Reception(acc: ReadSignal<Account>) -> impl IntoView {
view! {
<div
id="cafe-inventory"
id="cafe-voucher"
>
<InvForm />
<h1>
{move || format!("{}", acc.get())}
</h1>
<div
class="h-container"
>
<SwapButton
store=Store::Aldi
/>
<SwapButton
store=Store::Edeka
/>
<SwapButton
store=Store::Dm
/>
<SwapButton
store=Store::Lidl
/>
<SwapButton
store=Store::Rewe
/>
<SwapButton
store=Store::Tegut
/>
</div>
</div>
}
}
@ -26,7 +57,7 @@ fn StoreLogo(store: Store) -> impl IntoView {
<img
src=format!("assets/{}.svg", Into::<String>::into(&store))
class="logo"
// FIXME: Implement fmt trait for Store
// FIXME: Implement fmt::Display for Store
alt=format!("{:?}", store)
/>
}
@ -70,27 +101,6 @@ 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";
@ -140,8 +150,7 @@ fn AccRadio(acc: Account) -> impl IntoView {
<label
for=id.clone()
>
// FIXME: Implement fmt trait for Account
{format!("{:?}", acc)}
{format!("{}", acc)}
</label>
</div>
}

View file

@ -31,6 +31,27 @@ pub struct VoucherInventory {
pub count: i64,
}
#[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))
}
}
impl Into<String> for &Store {
fn into(self) -> String {
String::from(match *self {
@ -81,6 +102,15 @@ impl Into<String> for &Account {
}
}
impl std::fmt::Display for Account {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Account::Sumpf => "Sumpf",
Account::Heinersyndikat => "Heinersyndikat",
}.fmt(f)
}
}
#[cfg(feature = "server")]
impl ToSql for Store {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {