Lotsa Leptos
This commit is contained in:
parent
49a9810fd8
commit
8a25a5fa82
5 changed files with 115 additions and 19 deletions
|
@ -5,31 +5,105 @@ use leptos::task::spawn_local;
|
||||||
use bkbh_lib::types::*;
|
use bkbh_lib::types::*;
|
||||||
|
|
||||||
#[component]
|
#[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! {
|
view! {
|
||||||
<button
|
<button
|
||||||
on:click=move |_| {
|
on:click=move |_| {
|
||||||
spawn_local(async {
|
spawn_local(async move {
|
||||||
swap("aldi", 0).await.unwrap();
|
swap(store, 0).await.unwrap();
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
class="column"
|
||||||
>
|
>
|
||||||
<img
|
<StoreLogo store=store />
|
||||||
src="assets/aldi.svg"
|
|
||||||
class="logo"
|
|
||||||
alt="ALDI-Süd"
|
|
||||||
/>
|
|
||||||
</button>
|
</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() {
|
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(|| view! {
|
||||||
<SwapButton
|
<SwapButton
|
||||||
store=Store::Aldi
|
store=Store::Aldi
|
||||||
img_path=&"aldi"
|
|
||||||
pretty=&"Aldi"
|
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
id="cafe-inventory"
|
||||||
|
>
|
||||||
|
<InvForm />
|
||||||
|
</div>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use tauri_sys::Error;
|
use tauri_sys::Error;
|
||||||
use tauri_sys::core::invoke;
|
use tauri_sys::core::invoke;
|
||||||
|
use crate::types::*;
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct Swap<'a> {
|
pub struct Swap {
|
||||||
store: &'a str,
|
store: Store,
|
||||||
acc: i64,
|
acc: i64,
|
||||||
}
|
}
|
||||||
pub async fn swap(store: &str, acc: i64) -> Result<(), Error> {
|
pub async fn swap(store: Store, acc: i64) -> Result<(), Error> {
|
||||||
let args = Swap { store, acc };
|
let args = Swap { store, acc };
|
||||||
invoke("swap", &args).await
|
invoke("swap", &args).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use chrono::offset::Utc;
|
use chrono::offset::Utc;
|
||||||
use rusqlite::{types::ToSqlOutput, ToSql};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tauri::{Manager, State};
|
use tauri::State;
|
||||||
|
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
|
|
||||||
|
@ -61,12 +60,11 @@ pub async fn inventory(
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn swap(
|
pub async fn swap(
|
||||||
store: &str,
|
store: Store,
|
||||||
acc: i64,
|
acc: i64,
|
||||||
state: State<'_, Mutex<AppState>>,
|
state: State<'_, Mutex<AppState>>,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
let state = state.lock().await;
|
let state = state.lock().await;
|
||||||
let store: Store = store.try_into()?;
|
|
||||||
state.db.execute(
|
state.db.execute(
|
||||||
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
|
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||||
(
|
(
|
||||||
|
|
22
src/types.rs
22
src/types.rs
|
@ -31,6 +31,19 @@ pub struct VoucherInventory {
|
||||||
pub count: i64,
|
pub count: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<String> for &Store {
|
||||||
|
fn into(self) -> String {
|
||||||
|
String::from(match *self {
|
||||||
|
Store::Aldi => "aldi",
|
||||||
|
Store::Edeka => "edeka",
|
||||||
|
Store::Dm => "dm",
|
||||||
|
Store::Lidl => "lidl",
|
||||||
|
Store::Rewe => "rewe",
|
||||||
|
Store::Tegut => "tegut",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<&str> for Store {
|
impl TryFrom<&str> for Store {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
|
@ -59,6 +72,15 @@ impl TryFrom<&str> for Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<String> for &Account {
|
||||||
|
fn into(self) -> String {
|
||||||
|
String::from(match *self {
|
||||||
|
Account::Sumpf => "sumpf",
|
||||||
|
Account::Heinersyndikat => "hs",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[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<'_>> {
|
||||||
|
|
|
@ -106,7 +106,8 @@ input[type=number] {
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=radio] {
|
input[type=radio] {
|
||||||
height: 60%;
|
width: 100%;
|
||||||
|
height: 7mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
|
|
Loading…
Add table
Reference in a new issue