Refactor a bit
This commit is contained in:
parent
f18a360982
commit
185fd938c1
7 changed files with 194 additions and 188 deletions
|
@ -21,13 +21,8 @@ server = [
|
||||||
"dep:ring-compat",
|
"dep:ring-compat",
|
||||||
]
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
# The `_lib` suffix may seem redundant but it is necessary
|
name = "bkbh"
|
||||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
|
||||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
|
||||||
name = "bkbh_lib"
|
|
||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -1,185 +1,9 @@
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use bkbh_lib::commands::*;
|
use bkbh::leptos::cafe::Cafe;
|
||||||
use leptos::task::spawn_local;
|
|
||||||
use leptos::web_sys::FormData;
|
|
||||||
use leptos::form::FromFormData;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use bkbh_lib::types::*;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
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 move {
|
|
||||||
swap(store, 0).await.unwrap();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
class="column"
|
|
||||||
>
|
|
||||||
<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>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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));
|
|
||||||
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 SubmitButton() -> impl IntoView {
|
|
||||||
view! {
|
|
||||||
<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 />
|
|
||||||
<StoreInput store=Store::Dm />
|
|
||||||
<StoreInput store=Store::Lidl />
|
|
||||||
<StoreInput store=Store::Rewe />
|
|
||||||
<StoreInput store=Store::Tegut />
|
|
||||||
<CashInput value=cash />
|
|
||||||
<SubmitButton />
|
|
||||||
</form>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
leptos::mount::mount_to_body(|| view! {
|
leptos::mount::mount_to_body(
|
||||||
<SwapButton
|
|| view! { <Cafe /> }
|
||||||
store=Store::Aldi
|
);
|
||||||
/>
|
|
||||||
<div
|
|
||||||
id="cafe-inventory"
|
|
||||||
>
|
|
||||||
<InvForm />
|
|
||||||
</div>
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
bkbh_lib::run()
|
bkbh::run()
|
||||||
}
|
}
|
||||||
|
|
184
src/leptos/cafe.rs
Normal file
184
src/leptos/cafe.rs
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
use leptos::prelude::*;
|
||||||
|
use crate::commands::*;
|
||||||
|
use leptos::task::spawn_local;
|
||||||
|
use leptos::web_sys::FormData;
|
||||||
|
use leptos::form::FromFormData;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use crate::types::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Cafe() -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<SwapButton
|
||||||
|
store=Store::Aldi
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="cafe-inventory"
|
||||||
|
>
|
||||||
|
<InvForm />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
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 move {
|
||||||
|
swap(store, 0).await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
class="column"
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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));
|
||||||
|
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 SubmitButton() -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<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 />
|
||||||
|
<StoreInput store=Store::Dm />
|
||||||
|
<StoreInput store=Store::Lidl />
|
||||||
|
<StoreInput store=Store::Rewe />
|
||||||
|
<StoreInput store=Store::Tegut />
|
||||||
|
<CashInput value=cash />
|
||||||
|
<SubmitButton />
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
}
|
1
src/leptos/mod.rs
Normal file
1
src/leptos/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod cafe;
|
|
@ -1,6 +1,8 @@
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
#[cfg(feature = "leptos")]
|
||||||
|
pub mod leptos;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
#[cfg(all(feature = "tauri", feature="server"))]
|
#[cfg(all(feature = "tauri", feature="server"))]
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<link data-trunk rel="copy-dir" href="assets" />
|
<link data-trunk rel="copy-dir" href="assets" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Darmstadt sagt Nein zur Bezahlkartei!</title>
|
<title>Darmstadt sagt Nein zur Bezahlkartei!</title>
|
||||||
<link data-trunk rel="rust" href="." data-bin="leptos" data-wasm-opt="4" data-weak-refs />
|
<link data-trunk rel="rust" href="." data-bin="leptos" data-cargo-features="leptos" data-wasm-opt="4" data-weak-refs />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Add table
Reference in a new issue