From 8a25a5fa82e3859a1692b216a4ed10a9bb830261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bianca=20F=C3=BCrstenau?= Date: Sat, 22 Feb 2025 16:00:00 +0100 Subject: [PATCH] Lotsa Leptos --- src/bin/leptos.rs | 96 +++++++++++++++++++++++++++++++++++++++++------ src/commands.rs | 7 ++-- src/server/mod.rs | 6 +-- src/types.rs | 22 +++++++++++ styles.scss | 3 +- 5 files changed, 115 insertions(+), 19 deletions(-) diff --git a/src/bin/leptos.rs b/src/bin/leptos.rs index 4737730..37200df 100644 --- a/src/bin/leptos.rs +++ b/src/bin/leptos.rs @@ -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! { + ::into(&store)) + class="logo" + // FIXME: Implement fmt trait for Store + alt=format!("{:?}", store) + /> + } +} + +#[component] +fn SwapButton(store: Store) -> impl IntoView { view! { } } +#[component] +fn StoreInput(store: Store) -> impl IntoView { + let txt = format!("{}", Into::::into(&store)); + view! { +
+ + +
+ } +} + +#[component] +fn AccRadio(acc: Account) -> impl IntoView { + let txt = format!("{}", Into::::into(&acc)); + let id = format!("acc-{}", txt); + view! { +
+ + +
+ } +} + +#[component] +fn InvForm() -> impl IntoView { + view! { +
+ + + + + + + + + } +} + fn main() { console_error_panic_hook::set_once(); leptos::mount::mount_to_body(|| view! { +
+ +
}); } diff --git a/src/commands.rs b/src/commands.rs index d6e13ed..ee27cf3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,12 +1,13 @@ use tauri_sys::Error; use tauri_sys::core::invoke; +use crate::types::*; #[derive(serde::Serialize)] -pub struct Swap<'a> { - store: &'a str, +pub struct Swap { + store: Store, 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 }; invoke("swap", &args).await } diff --git a/src/server/mod.rs b/src/server/mod.rs index 1595f83..56072e3 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,8 +1,7 @@ use chrono::offset::Utc; -use rusqlite::{types::ToSqlOutput, ToSql}; use std::collections::HashMap; use tokio::sync::Mutex; -use tauri::{Manager, State}; +use tauri::State; use crate::types::*; @@ -61,12 +60,11 @@ pub async fn inventory( #[tauri::command] pub async fn swap( - store: &str, + store: Store, acc: i64, state: State<'_, Mutex>, ) -> Result<(), ()> { let state = state.lock().await; - let store: Store = store.try_into()?; state.db.execute( "INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)", ( diff --git a/src/types.rs b/src/types.rs index eb4ac68..d774769 100644 --- a/src/types.rs +++ b/src/types.rs @@ -31,6 +31,19 @@ pub struct VoucherInventory { pub count: i64, } +impl Into 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 { type Error = (); @@ -59,6 +72,15 @@ impl TryFrom<&str> for Account { } } +impl Into for &Account { + fn into(self) -> String { + String::from(match *self { + Account::Sumpf => "sumpf", + Account::Heinersyndikat => "hs", + }) + } +} + #[cfg(feature = "server")] impl ToSql for Store { fn to_sql(&self) -> rusqlite::Result> { diff --git a/styles.scss b/styles.scss index d239b06..645a0ee 100644 --- a/styles.scss +++ b/styles.scss @@ -106,7 +106,8 @@ input[type=number] { } input[type=radio] { - height: 60%; + width: 100%; + height: 7mm; } button:hover {