Compare commits

...

2 commits

Author SHA1 Message Date
Bianca Fürstenau
be9b5ed855 Fmt 2025-03-05 20:15:11 +01:00
Bianca Fürstenau
eda34db508 Refactor 2025-03-05 20:05:46 +01:00
13 changed files with 68 additions and 57 deletions

4
leptosfmt.toml Normal file
View file

@ -0,0 +1,4 @@
max_width = 80
tab_spaces = 8
indentation_style = "Tabs"
newline_style = "Unix"

2
rust-analyzer.toml Normal file
View file

@ -0,0 +1,2 @@
[rustfmt]
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]

View file

@ -1,3 +1,4 @@
edition = "2024"
max_width = 80 max_width = 80
hard_tabs = true hard_tabs = true
tab_spaces = 8 tab_spaces = 8

View file

@ -1,9 +1,7 @@
use leptos::prelude::*;
use bkbh::leptos::cafe::Cafe; use bkbh::leptos::cafe::Cafe;
use leptos::prelude::*;
fn main() { fn main() {
console_error_panic_hook::set_once(); console_error_panic_hook::set_once();
leptos::mount::mount_to_body( leptos::mount::mount_to_body(|| view! { <Cafe /> });
|| view! { <Cafe /> }
);
} }

View file

@ -1,7 +1,7 @@
use tauri_sys::Error;
use tauri_sys::core::invoke;
use crate::types::*; use crate::types::*;
use std::collections::HashMap; use std::collections::HashMap;
use tauri_sys::core::invoke;
use tauri_sys::Error;
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
pub struct Swap { pub struct Swap {

8
src/leptos/angel.rs Normal file
View file

@ -0,0 +1,8 @@
use leptos::prelude::*;
#[component]
pub fn Angel() -> impl IntoView {
view! {
<p>Hi</p>
}
}

View file

@ -1,10 +1,10 @@
use leptos::prelude::*;
use crate::commands::*; use crate::commands::*;
use crate::types::*;
use leptos::form::FromFormData;
use leptos::prelude::*;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use leptos::web_sys::FormData; use leptos::web_sys::FormData;
use leptos::form::FromFormData;
use std::collections::HashMap; use std::collections::HashMap;
use crate::types::*;
#[component] #[component]
pub fn Cafe() -> impl IntoView { pub fn Cafe() -> impl IntoView {
@ -13,6 +13,7 @@ pub fn Cafe() -> impl IntoView {
<Reception <Reception
acc=acc.0 acc=acc.0
/> />
<InvForm />
} }
} }
@ -51,18 +52,6 @@ fn Reception(acc: ReadSignal<Account>) -> impl IntoView {
} }
} }
#[component]
fn StoreLogo(store: Store) -> impl IntoView {
view! {
<img
src=format!("assets/{}.svg", Into::<String>::into(&store))
class="logo"
// FIXME: Implement fmt::Display for Store
alt=format!("{:?}", store)
/>
}
}
#[component] #[component]
fn SwapButton(store: Store) -> impl IntoView { fn SwapButton(store: Store) -> impl IntoView {
view! { view! {
@ -74,7 +63,7 @@ fn SwapButton(store: Store) -> impl IntoView {
} }
class="column" class="column"
> >
<StoreLogo store=store /> <super::store::Logo store=store />
</button> </button>
} }
} }
@ -89,7 +78,7 @@ fn StoreInput(store: Store) -> impl IntoView {
<label <label
for=txt.clone() for=txt.clone()
> >
<StoreLogo store=store /> <super::store::Logo store=store />
</label> </label>
<input <input
type="number" type="number"

View file

@ -1 +1,3 @@
pub mod angel;
pub mod cafe; pub mod cafe;
pub mod store;

14
src/leptos/store.rs Normal file
View file

@ -0,0 +1,14 @@
use crate::types::*;
use leptos::prelude::*;
#[component]
pub fn Logo(store: Store) -> impl IntoView {
view! {
<img
src=format!("assets/{}.svg", Into::<String>::into(&store))
class="logo"
// FIXME: Implement fmt::Display for Store
alt=format!("{:?}", store)
/>
}
}

View file

@ -1,16 +1,16 @@
pub mod commands; pub mod commands;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "leptos")] #[cfg(feature = "leptos")]
pub mod leptos; pub mod leptos;
#[cfg(feature = "server")]
pub mod server;
pub mod types; pub mod types;
#[cfg(all(feature = "tauri", feature = "server"))] #[cfg(all(feature = "tauri", feature = "server"))]
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
use server::app_state::AppState;
use tauri::{Manager, State}; use tauri::{Manager, State};
use tauri_plugin_fs::FsExt; use tauri_plugin_fs::FsExt;
use server::app_state::AppState;
use tokio::sync::Mutex; use tokio::sync::Mutex;
let state = AppState::new(); let state = AppState::new();

View file

@ -1,8 +1,8 @@
use chrono::offset::Utc; use chrono::offset::Utc;
use curl::{easy, easy::Easy2}; use curl::{easy, easy::Easy2};
use rand::prelude::*; use rand::prelude::*;
use rusqlite::{Connection, DatabaseName};
use ring_compat::signature::ed25519::SigningKey; use ring_compat::signature::ed25519::SigningKey;
use rusqlite::{Connection, DatabaseName};
use tauri::{Manager, State}; use tauri::{Manager, State};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -62,7 +62,8 @@ fn data_client(file: &str) -> Result<Easy2<Collector>, ()> {
file file
); );
client.url(&url).map_err(|_| ())?; client.url(&url).map_err(|_| ())?;
client.username(include_str!("cloud_user.txt")).map_err(|_| ())?; client.username(include_str!("cloud_user.txt"))
.map_err(|_| ())?;
client.http_auth(easy::Auth::new().auto(true)) client.http_auth(easy::Auth::new().auto(true))
.map_err(|_| ())?; .map_err(|_| ())?;
client.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem")) client.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem"))
@ -76,8 +77,7 @@ fn put_client(file: &str, payload: &[u8]) -> Result<Easy2<Collector>, ()> {
client.get_mut().1.extend_from_slice(payload); client.get_mut().1.extend_from_slice(payload);
client.in_filesize(payload.len() as u64) client.in_filesize(payload.len() as u64)
.map_err(|e| println!("{:?}", e))?; .map_err(|e| println!("{:?}", e))?;
client.upload(true) client.upload(true).map_err(|e| println!("{:?}", e))?;
.map_err(|e| println!("{:?}", e))?;
Ok(client) Ok(client)
} }
@ -96,22 +96,21 @@ async fn push_key(id: &u64, key: &SigningKey) -> Result<(), ()> {
let file = format!("{:016X}.key", id); let file = format!("{:016X}.key", id);
let v_key = key.verifying_key(); let v_key = key.verifying_key();
let client = put_client(&file, v_key.as_ref())?; let client = put_client(&file, v_key.as_ref())?;
let _perf = client.perform() let _perf = client.perform().map_err(|e| println!("{:?}", e))?;
.map_err(|e| println!("{:?}", e))?;
Ok(()) Ok(())
} }
fn push_db(id: &u64, db: &Connection, app: tauri::AppHandle) -> Result<(), ()> { fn push_db(id: &u64, db: &Connection, app: tauri::AppHandle) -> Result<(), ()> {
let filename = format!("{:016X}.sqlite", id); let filename = format!("{:016X}.sqlite", id);
let path = app.path().resolve(&filename, tauri::path::BaseDirectory::Temp) let path = app
.path()
.resolve(&filename, tauri::path::BaseDirectory::Temp)
.map_err(|e| println!("{:?}", e))?; .map_err(|e| println!("{:?}", e))?;
db.backup(DatabaseName::Main, &path, None) db.backup(DatabaseName::Main, &path, None)
.map_err(|e| println!("{:?}", e))?; .map_err(|e| println!("{:?}", e))?;
let buf = std::fs::read(&path) let buf = std::fs::read(&path).map_err(|e| println!("{:?}", e))?;
.map_err(|e| println!("{:?}", e))?;
let client = put_client(&filename, buf.as_ref())?; let client = put_client(&filename, buf.as_ref())?;
let _perf = client.perform() let _perf = client.perform().map_err(|e| println!("{:?}", e))?;
.map_err(|e| println!("{:?}", e))?;
Ok(()) Ok(())
} }

View file

@ -1,7 +1,7 @@
use chrono::offset::Utc; use chrono::offset::Utc;
use std::collections::HashMap; use std::collections::HashMap;
use tokio::sync::Mutex;
use tauri::State; use tauri::State;
use tokio::sync::Mutex;
use crate::types::*; use crate::types::*;
@ -29,7 +29,7 @@ fn parse_inventory(data: HashMap<String, String>) -> Result<Inventory, ()> {
}; };
let v = VoucherInventory { store, count }; let v = VoucherInventory { store, count };
vouchers.push(v); vouchers.push(v);
}, }
} }
} }
unimplemented!() unimplemented!()
@ -47,15 +47,10 @@ pub async fn inventory(
for v in inv.vouchers { for v in inv.vouchers {
state.db.execute( state.db.execute(
"INSERT INTO voucher_inventory VALUES ()", "INSERT INTO voucher_inventory VALUES ()",
( (inv.acc, v.store, v.count, now),
inv.acc,
v.store,
v.count,
now,
),
) )
.map_err(|e| println!("{:?}", e))?; .map_err(|e| println!("{:?}", e))?;
}; }
Ok(()) Ok(())
} }

View file

@ -1,6 +1,6 @@
#[cfg(feature = "server")] #[cfg(feature = "server")]
use rusqlite::{types::ToSqlOutput, ToSql}; use rusqlite::{types::ToSqlOutput, ToSql};
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Store { pub enum Store {
@ -43,9 +43,7 @@ impl std::str::FromStr for Cash {
.map_err(|e| println!("{:?}", e))?; .map_err(|e| println!("{:?}", e))?;
let f = match split.get(1) { let f = match split.get(1) {
None => 0, None => 0,
Some(fs) => i64::from_str( Some(fs) => i64::from_str(&format!("00{}", fs)[0..2])
&format!("00{}", fs)[0..2]
)
.map_err(|e| println!("{:?}", e))?, .map_err(|e| println!("{:?}", e))?,
}; };
Ok(Cash(i * 100 + f)) Ok(Cash(i * 100 + f))
@ -107,7 +105,8 @@ impl std::fmt::Display for Account {
match *self { match *self {
Account::Sumpf => "Sumpf", Account::Sumpf => "Sumpf",
Account::Heinersyndikat => "Heinersyndikat", Account::Heinersyndikat => "Heinersyndikat",
}.fmt(f) }
.fmt(f)
} }
} }