More swap buttons again
This commit is contained in:
parent
9e49770b99
commit
7cc7f03e5c
2 changed files with 67 additions and 28 deletions
|
@ -8,14 +8,45 @@ use crate::types::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Cafe() -> impl IntoView {
|
pub fn Cafe() -> impl IntoView {
|
||||||
|
let acc = signal(Account::Sumpf);
|
||||||
view! {
|
view! {
|
||||||
<SwapButton
|
<Reception
|
||||||
store=Store::Aldi
|
acc=acc.0
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn Reception(acc: ReadSignal<Account>) -> impl IntoView {
|
||||||
|
view! {
|
||||||
<div
|
<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>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +57,7 @@ fn StoreLogo(store: Store) -> impl IntoView {
|
||||||
<img
|
<img
|
||||||
src=format!("assets/{}.svg", Into::<String>::into(&store))
|
src=format!("assets/{}.svg", Into::<String>::into(&store))
|
||||||
class="logo"
|
class="logo"
|
||||||
// FIXME: Implement fmt trait for Store
|
// FIXME: Implement fmt::Display for Store
|
||||||
alt=format!("{:?}", 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]
|
#[component]
|
||||||
fn CashInput(value: RwSignal<String>) -> impl IntoView {
|
fn CashInput(value: RwSignal<String>) -> impl IntoView {
|
||||||
let txt = "cash";
|
let txt = "cash";
|
||||||
|
@ -140,8 +150,7 @@ fn AccRadio(acc: Account) -> impl IntoView {
|
||||||
<label
|
<label
|
||||||
for=id.clone()
|
for=id.clone()
|
||||||
>
|
>
|
||||||
// FIXME: Implement fmt trait for Account
|
{format!("{}", acc)}
|
||||||
{format!("{:?}", acc)}
|
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
30
src/types.rs
30
src/types.rs
|
@ -31,6 +31,27 @@ pub struct VoucherInventory {
|
||||||
pub count: i64,
|
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 {
|
impl Into<String> for &Store {
|
||||||
fn into(self) -> String {
|
fn into(self) -> String {
|
||||||
String::from(match *self {
|
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")]
|
#[cfg(feature = "server")]
|
||||||
impl ToSql for Store {
|
impl ToSql for Store {
|
||||||
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
|
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue