Leptos updated to 0.5

main
Josef Rokos 2 years ago
parent 9dd0993204
commit bbad2bb183

133
Cargo.lock generated

@ -592,28 +592,24 @@ dependencies = [
[[package]] [[package]]
name = "cached" name = "cached"
version = "0.44.0" version = "0.45.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700" checksum = "90eb5776f28a149524d1d8623035760b4454ec881e8cf3838fa8d7e1b11254b3"
dependencies = [ dependencies = [
"async-trait",
"cached_proc_macro", "cached_proc_macro",
"cached_proc_macro_types", "cached_proc_macro_types",
"futures",
"hashbrown 0.13.2", "hashbrown 0.13.2",
"instant", "instant",
"once_cell", "once_cell",
"thiserror", "thiserror",
"tokio",
] ]
[[package]] [[package]]
name = "cached_proc_macro" name = "cached_proc_macro"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b48814962d2fd604c50d2b9433c2a41a0ab567779ee2c02f7fba6eca1221f082" checksum = "7da8245dd5f576a41c3b76247b54c15b0e43139ceeb4f732033e15be7c005176"
dependencies = [ dependencies = [
"cached_proc_macro_types",
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -977,18 +973,6 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408" checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408"
[[package]]
name = "educe"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "079044df30bb07de7d846d41a184c4b00e66ebdac93ee459253474f3a47e50ae"
dependencies = [
"enum-ordinalize",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.8.1" version = "1.8.1"
@ -1007,19 +991,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "enum-ordinalize"
version = "3.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4f76552f53cefc9a7f64987c3701b99d982f7690606fd67de1d09712fbf52f1"
dependencies = [
"num-bigint",
"num-traits",
"proc-macro2",
"quote",
"syn 2.0.28",
]
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -1627,9 +1598,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos" name = "leptos"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d08fd7674758f996050217a8aff9e584d033c2e5c882cd3f52fb5090dc361dd" checksum = "4d811de15430df8e4886afe09e5e741a886876c51ea32b8f11e0963ba9415e4b"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"leptos_config", "leptos_config",
@ -1640,13 +1611,16 @@ dependencies = [
"server_fn", "server_fn",
"tracing", "tracing",
"typed-builder", "typed-builder",
"typed-builder-macro",
"wasm-bindgen",
"web-sys",
] ]
[[package]] [[package]]
name = "leptos_actix" name = "leptos_actix"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c122547e0a04d6b2efaef999b3165f03eb1b1284fdb298f05bde9107ed16ec2" checksum = "82ae271646ca49e2464ee454428775064a330658559e1c92d20170ee9c12b674"
dependencies = [ dependencies = [
"actix-http", "actix-http",
"actix-web", "actix-web",
@ -1658,14 +1632,15 @@ dependencies = [
"parking_lot", "parking_lot",
"regex", "regex",
"serde_json", "serde_json",
"tokio",
"tracing", "tracing",
] ]
[[package]] [[package]]
name = "leptos_config" name = "leptos_config"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e5c13a1ae92b5a545cc013205288751fb2fef521de5a092067fd8429ad343e8" checksum = "92015175317cafe8e651289a48bc3cdd68c276c6054229f20dbee73a81fea21f"
dependencies = [ dependencies = [
"config", "config",
"regex", "regex",
@ -1676,14 +1651,13 @@ dependencies = [
[[package]] [[package]]
name = "leptos_dom" name = "leptos_dom"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35994afab1dca68a46c7b40a29d40d84a2e06e1b1fa0d5c5915ade4f4f2611ee" checksum = "ba03b4357fd08d2c84da3572f66f47973703e0ef6166c2dd0db4766f83310a72"
dependencies = [ dependencies = [
"async-recursion", "async-recursion",
"cfg-if", "cfg-if",
"drain_filter_polyfill", "drain_filter_polyfill",
"educe",
"futures", "futures",
"getrandom", "getrandom",
"html-escape", "html-escape",
@ -1695,6 +1669,7 @@ dependencies = [
"pad-adapter", "pad-adapter",
"paste", "paste",
"rustc-hash", "rustc-hash",
"serde",
"serde_json", "serde_json",
"server_fn", "server_fn",
"smallvec", "smallvec",
@ -1706,9 +1681,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_hot_reload" name = "leptos_hot_reload"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a088a4dd5489941a9cc73719148f217c78f0d761a50e025739653c3b7f9d484" checksum = "21cade49ea1a5e72b3a546b4507b3ef4e43586d306b7f20c180ed6a3bf855665"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"camino", "camino",
@ -1724,9 +1699,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_integration_utils" name = "leptos_integration_utils"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfd4a097f1870172f5079e44af99fb5d5f02cd856db6b32a6ac98cc58f1a1f47" checksum = "cb2d6a0d32b073fa1a9326f83b99f02f60a0e159fe0a7ce53d2708318114a6a3"
dependencies = [ dependencies = [
"futures", "futures",
"leptos", "leptos",
@ -1738,9 +1713,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_macro" name = "leptos_macro"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bdd7a21d20ca21bb12d67d050d4b0ad9973b156bce98f499f8b1789f11959dd" checksum = "befb8d664269550a918a6a160c10792951a37e95b542ca454c191ec7480505de"
dependencies = [ dependencies = [
"attribute-derive", "attribute-derive",
"cfg-if", "cfg-if",
@ -1761,9 +1736,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_meta" name = "leptos_meta"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed4e4855b6d0047f1cdbf0e9d41b76a1b596ec374f844d2bae1e48f2d2df70d8" checksum = "6c77f3ae209084fae41024f3023fa816a6fe91a45da00729ff349dd0ddb9b2c0"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"indexmap 2.0.0", "indexmap 2.0.0",
@ -1775,9 +1750,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_reactive" name = "leptos_reactive"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5500318e457b4ab841722a5988e8db0def1ee7ac66b816ba9073c100c4984a" checksum = "4382426f6e79d209408e362883b9542f934bafb3b98cc957f94e085f707508a0"
dependencies = [ dependencies = [
"base64 0.21.2", "base64 0.21.2",
"cfg-if", "cfg-if",
@ -1800,9 +1775,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_router" name = "leptos_router"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a6cd29a56992923c9bad3c814ab9d7a78bf0bfec80c8f4dfbf049144fa5828" checksum = "b250d706ddbfb9991c5615b35dd27596e5b23024d8ee50fe4717aa21f67bb3b1"
dependencies = [ dependencies = [
"cached", "cached",
"cfg-if", "cfg-if",
@ -1812,7 +1787,6 @@ dependencies = [
"lazy_static", "lazy_static",
"leptos", "leptos",
"linear-map", "linear-map",
"log",
"lru", "lru",
"once_cell", "once_cell",
"percent-encoding", "percent-encoding",
@ -1830,9 +1804,9 @@ dependencies = [
[[package]] [[package]]
name = "leptos_server" name = "leptos_server"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28d958deee3c7ffda892a67ac4a47500aebbaf00b11d217cfe6fd494c297818" checksum = "0dfe03995c38441e45dc0d44828b657dbcff3b87c8ce5c2f4219297226c752b0"
dependencies = [ dependencies = [
"inventory", "inventory",
"lazy_static", "lazy_static",
@ -1925,11 +1899,11 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]] [[package]]
name = "lru" name = "lru"
version = "0.10.0" version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03f1160296536f10c833a82dca22267d5486734230d47bf00bf435885814ba1e" checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21"
dependencies = [ dependencies = [
"hashbrown 0.13.2", "hashbrown 0.14.0",
] ]
[[package]] [[package]]
@ -2824,9 +2798,9 @@ dependencies = [
[[package]] [[package]]
name = "server_fn" name = "server_fn"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "644216cf54c944da2d7fc7a75337a35dc39de19130be3fd88fd58674719a1b5b" checksum = "0c5839ea169c9ac14c08d368ed523d0896b050cf18d754fcbde19923995f19be"
dependencies = [ dependencies = [
"ciborium", "ciborium",
"const_format", "const_format",
@ -2849,9 +2823,9 @@ dependencies = [
[[package]] [[package]]
name = "server_fn_macro" name = "server_fn_macro"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1db2cd1a054f5c6ec168982241f6cdad083591d6c68449e666c839ec421bfc54" checksum = "80116501286c018b8d6330be8b2bc286ed801f59439f2fbfad2b79d96942c2a2"
dependencies = [ dependencies = [
"const_format", "const_format",
"proc-macro-error", "proc-macro-error",
@ -2864,9 +2838,9 @@ dependencies = [
[[package]] [[package]]
name = "server_fn_macro_default" name = "server_fn_macro_default"
version = "0.4.8" version = "0.5.0-rc1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35ee7b18c66e7a30b1855096cee24d540925825ce91193f42fae322033b109c1" checksum = "709cc458808a38f20b9d0121a3022fa35b704e5e577d352b92b5dd4ad78f4923"
dependencies = [ dependencies = [
"server_fn_macro", "server_fn_macro",
"syn 2.0.28", "syn 2.0.28",
@ -3358,21 +3332,9 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"socket2", "socket2",
"tokio-macros",
"windows-sys", "windows-sys",
] ]
[[package]]
name = "tokio-macros"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.28",
]
[[package]] [[package]]
name = "tokio-stream" name = "tokio-stream"
version = "0.1.14" version = "0.1.14"
@ -3454,13 +3416,22 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]] [[package]]
name = "typed-builder" name = "typed-builder"
version = "0.14.0" version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64cba322cb9b7bc6ca048de49e83918223f35e7a86311267013afff257004870" checksum = "6605aaa56cce0947127ffa0675a8a1b181f87773364390174de60a86ab9085f1"
dependencies = [
"typed-builder-macro",
]
[[package]]
name = "typed-builder-macro"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a6a6884f6a890a012adcc20ce498f30ebdc70fb1ea242c333cc5f435b0b3871"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.28",
] ]
[[package]] [[package]]

@ -12,10 +12,10 @@ actix-web = { version = "4", optional = true, features = ["macros"] }
actix-session = { version = "0.7.2", optional = true, features = ["cookie-session"] } actix-session = { version = "0.7.2", optional = true, features = ["cookie-session"] }
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
cfg-if = "1" cfg-if = "1"
leptos = { version = "0.4.8" } leptos = { version = "0.5.0-rc1" }
leptos_meta = { version = "0.4.8" } leptos_meta = { version = "0.5.0-rc1" }
leptos_actix = { version = "0.4.8", optional = true } leptos_actix = { version = "0.5.0-rc1", optional = true }
leptos_router = { version = "0.4.8" } leptos_router = { version = "0.5.0-rc1" }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
wasm-bindgen = "=0.2.87" wasm-bindgen = "=0.2.87"
web-sys = { version = "0.3.61", features = ["Navigator"] } web-sys = { version = "0.3.61", features = ["Navigator"] }

@ -6,13 +6,12 @@ use crate::pages::home_page::HomePage;
use crate::pages::settings::Settings; use crate::pages::settings::Settings;
#[component] #[component]
pub fn App(cx: Scope) -> impl IntoView { pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc. // Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context(cx); provide_meta_context();
//provide_context(cx, DialogOpener::new(cx)); //provide_context(DialogOpener::new());
view! { view! {
cx,
<Html <Html
lang="cz" lang="cz"
dir="ltr" dir="ltr"
@ -61,7 +60,7 @@ pub fn App(cx: Scope) -> impl IntoView {
<li class="menu-item"> <li class="menu-item">
<a href="/" class="menu-link"> <a href="/" class="menu-link">
<i class="menu-icon tf-icons bx bx-home-circle"></i> <i class="menu-icon tf-icons bx bx-home-circle"></i>
<div data-i18n="Analytics">{trl(cx, "Dashboard")}</div> <div data-i18n="Analytics">{trl("Dashboard")}</div>
</a> </a>
</li> </li>
<li class="menu-item"> <li class="menu-item">
@ -173,8 +172,8 @@ pub fn App(cx: Scope) -> impl IntoView {
<Router> <Router>
<main> <main>
<Routes> <Routes>
<Route path="" view=|cx| view! { cx, <HomePage/> }/> <Route path="" view=|| view! { <HomePage/> }/>
<Route path="settings" view=|cx| view! { cx, <Settings/> }/> <Route path="settings" view=|| view! { <Settings/> }/>
</Routes> </Routes>
</main> </main>
</Router> </Router>
@ -212,7 +211,7 @@ pub fn App(cx: Scope) -> impl IntoView {
<Router> <Router>
<main> <main>
<Routes> <Routes>
<Route path="" view=|cx| view! { cx, <HomePage/> }/> <Route path="" view=|| view! { <HomePage/> }/>
</Routes> </Routes>
</main> </main>
</Router> </Router>

@ -2,16 +2,12 @@ use crate::backend::data::Company;
use leptos::*; use leptos::*;
#[server(GetCompany, "/api", "Url", "get_company")] #[server(GetCompany, "/api", "Url", "get_company")]
pub async fn get_company(cx: Scope) -> Result<Company, ServerFnError> { pub async fn get_company() -> Result<Company, ServerFnError> {
use crate::backend::AppData; use crate::backend::AppData;
use actix_web::web::Data; use actix_web::web::Data;
use leptos_actix::extract; use leptos_actix::extract;
let pool = extract( let pool = extract(|data: Data<AppData>| async move { data.db_pool().clone() }).await?;
cx,
|data: Data<AppData>| async move { data.db_pool().clone() },
)
.await?;
let cmp = sqlx::query_as::<_, Company>("SELECT * FROM company") let cmp = sqlx::query_as::<_, Company>("SELECT * FROM company")
.fetch_one(&pool) .fetch_one(&pool)
@ -21,16 +17,12 @@ pub async fn get_company(cx: Scope) -> Result<Company, ServerFnError> {
} }
#[server(UpdateCompany, "/api", "Url", "update_company")] #[server(UpdateCompany, "/api", "Url", "update_company")]
pub async fn update_company(cx: Scope, company: Company) -> Result<(), ServerFnError> { pub async fn update_company(company: Company) -> Result<(), ServerFnError> {
use crate::backend::AppData; use crate::backend::AppData;
use actix_web::web::Data; use actix_web::web::Data;
use leptos_actix::extract; use leptos_actix::extract;
let pool = extract( let pool = extract(|data: Data<AppData>| async move { data.db_pool().clone() }).await?;
cx,
|data: Data<AppData>| async move { data.db_pool().clone() },
)
.await?;
sqlx::query( sqlx::query(
"UPDATE company SET name = $1, street = $2, house_number = $3, zip_code = $4, city = $5 \ "UPDATE company SET name = $1, street = $2, house_number = $3, zip_code = $4, city = $5 \

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use validator::Validate; use validator::Validate;
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate)] #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)]
#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] #[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
pub struct Company { pub struct Company {
id: i32, id: i32,

@ -8,8 +8,8 @@ pub struct DialogOpener {
} }
impl DialogOpener { impl DialogOpener {
pub fn new(cx: Scope) -> Self { pub fn new() -> Self {
let (visible, set_visible) = create_signal(cx, false); let (visible, set_visible) = create_signal(false);
DialogOpener { DialogOpener {
visible, visible,
set_visible, set_visible,
@ -31,19 +31,18 @@ impl DialogOpener {
#[component] #[component]
pub fn ModalDialog( pub fn ModalDialog(
cx: Scope,
opener: DialogOpener, opener: DialogOpener,
title: &'static str, title: &'static str,
children: Children, children: Children,
) -> impl IntoView { ) -> impl IntoView {
view! {cx, view! {
<div class={ move || if opener.visible() {"modal fade show"} else {"modal fade"}} <div class={ move || if opener.visible() {"modal fade show"} else {"modal fade"}}
style={ move || if opener.visible() {"display: block;"} else {""}} style={ move || if opener.visible() {"display: block;"} else {""}}
id="modalCenter" tabindex="-1" aria-hidden="true"> id="modalCenter" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="modalCenterTitle">{trl(cx, title)}</h5> <h5 class="modal-title" id="modalCenterTitle">{trl(title)}</h5>
<button <button
type="button" type="button"
class="btn-close" class="btn-close"
@ -51,7 +50,7 @@ pub fn ModalDialog(
aria-label="Close" aria-label="Close"
on:click=move |_| opener.hide()/> on:click=move |_| opener.hide()/>
</div> </div>
{children(cx)} {children()}
</div> </div>
</div> </div>
</div> </div>
@ -59,33 +58,33 @@ pub fn ModalDialog(
} }
#[component] #[component]
pub fn ModalBody(cx: Scope, children: Children) -> impl IntoView { pub fn ModalBody(children: Children) -> impl IntoView {
view! {cx, view! {
<div class="modal-body"> <div class="modal-body">
{children(cx)} {children()}
</div> </div>
} }
} }
#[component] #[component]
pub fn ModalFooter(cx: Scope, children: Children) -> impl IntoView { pub fn ModalFooter(children: Children) -> impl IntoView {
view! {cx, view! {
<div class="modal-footer"> <div class="modal-footer">
{children(cx)} {children()}
</div> </div>
} }
} }
#[component] #[component]
pub fn DlgNotLoaded(cx: Scope, opener: DialogOpener, title: &'static str) -> impl IntoView { pub fn DlgNotLoaded(opener: DialogOpener, title: &'static str) -> impl IntoView {
view! {cx, view! {
<ModalDialog opener=opener title=title> <ModalDialog opener=opener title=title>
<ModalBody> <ModalBody>
<div>{trl(cx, "Entity not loaded")}</div> <div>{trl("Entity not loaded")}</div>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal" on:click=move |_| opener.hide()> <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal" on:click=move |_| opener.hide()>
{trl(cx, "Close")} {trl("Close")}
</button> </button>
</ModalFooter> </ModalFooter>
</ModalDialog> </ModalDialog>

@ -3,24 +3,23 @@ use leptos::*;
#[component] #[component]
pub fn ServerErr( pub fn ServerErr(
cx: Scope,
result: RwSignal<Option<Result<(), ServerFnError>>>, result: RwSignal<Option<Result<(), ServerFnError>>>,
opener: DialogOpener, opener: DialogOpener,
) -> impl IntoView { ) -> impl IntoView {
view! {cx, {move || { view! {{move || {
if let Some(val) = result.get() { if let Some(val) = result.get() {
if let Err(e) = val { if let Err(e) = val {
view! {cx, view! {
<div class="alert alert-danger"> <div class="alert alert-danger">
"Server error: " {e.to_string()} "Server error: " {e.to_string()}
</div> </div>
} }
} else { } else {
opener.hide(); opener.hide();
view! {cx, <div></div>} view! {<div></div>}
} }
} else { } else {
view! {cx, <div></div>} view! {<div></div>}
} }
}} }}
} }

@ -4,33 +4,32 @@ use crate::validator::Validator;
#[component] #[component]
pub fn ValidationErr( pub fn ValidationErr(
cx: Scope,
validator: Validator, validator: Validator,
) -> impl IntoView { ) -> impl IntoView {
view! {cx, {move || { view! {{move || {
if !validator.is_valid() { if !validator.is_valid() {
if let Some(msgs) = validator.messages() { if let Some(msgs) = validator.messages() {
let out_msgs = msgs.into_iter().map(move |e| { let out_msgs = msgs.into_iter().map(move |e| {
view! {cx, view! {
<div class="alert alert-danger"> <div class="alert alert-danger">
{trl(cx, &e)} {trl(&e)}
</div> </div>
} }
}).collect_view(cx); }).collect_view();
view! {cx, view! {
<div> <div>
{out_msgs} {out_msgs}
</div> </div>
} }
} else { } else {
view! {cx, view! {
<div class="alert alert-danger"> <div class="alert alert-danger">
"Validation error" "Validation error"
</div> </div>
} }
} }
} else { } else {
view! {cx, <div></div>} view! {<div></div>}
} }
}} }}
} }

@ -20,8 +20,8 @@ if #[cfg(feature = "hydrate")] {
console_error_panic_hook::set_once(); console_error_panic_hook::set_once();
leptos::mount_to_body(move |cx| { leptos::mount_to_body(move || {
view! { cx, <App/> } view! { <App/> }
}); });
} }
} }

@ -24,10 +24,10 @@ lazy_static! {
}; };
} }
fn get_locales(cx: Scope) -> Vec<Option<String>> { fn get_locales() -> Vec<Option<String>> {
let (loc, set_loc) = create_signal(cx, Vec::new()); let (loc, set_loc) = create_signal(Vec::new());
create_effect(cx, move |_| { create_effect(move |_| {
let js_locales = window().navigator().languages(); let js_locales = window().navigator().languages();
set_loc.update(|l| *l = js_locales.into_iter().map(|val| val.as_string()).collect::<Vec<_>>()); set_loc.update(|l| *l = js_locales.into_iter().map(|val| val.as_string()).collect::<Vec<_>>());
}); });
@ -35,8 +35,8 @@ fn get_locales(cx: Scope) -> Vec<Option<String>> {
loc.get_untracked() loc.get_untracked()
} }
pub fn get_dictionary(cx: Scope) -> Option<&'static HashMap<&'static str, &'static str>> { pub fn get_dictionary() -> Option<&'static HashMap<&'static str, &'static str>> {
let locs = get_locales(cx); let locs = get_locales();
for loc in locs { for loc in locs {
if let Some(key) = loc { if let Some(key) = loc {

@ -5,9 +5,9 @@ use crate::locales::catalogues::get_dictionary;
mod catalogues; mod catalogues;
pub fn trl(cx: Scope, phrase: &str) -> impl Fn() -> String { pub fn trl(phrase: &str) -> impl Fn() -> String {
let mut translated = phrase; let mut translated = phrase;
if let Some(dict) = get_dictionary(cx) { if let Some(dict) = get_dictionary() {
if let Some(p) = dict.get(phrase.to_string().as_str()) { if let Some(p) = dict.get(phrase.to_string().as_str()) {
translated = *p; translated = *p;
} }

@ -1,3 +1,4 @@
use actix_web::middleware::DefaultHeaders;
use sqlx::migrate; use sqlx::migrate;
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
@ -18,7 +19,7 @@ async fn main() -> std::io::Result<()> {
let conf = get_configuration(None).await.unwrap(); let conf = get_configuration(None).await.unwrap();
let addr = conf.leptos_options.site_addr; let addr = conf.leptos_options.site_addr;
// Generate the list of routes in your Leptos App // Generate the list of routes in your Leptos App
let routes = generate_route_list(|cx| view! { cx, <App/> }); let routes = generate_route_list(|| view! { <App/> });
let key = Key::generate(); let key = Key::generate();
let pool = PgPoolOptions::new() let pool = PgPoolOptions::new()
@ -41,7 +42,7 @@ async fn main() -> std::io::Result<()> {
.leptos_routes( .leptos_routes(
leptos_options.to_owned(), leptos_options.to_owned(),
routes.to_owned(), routes.to_owned(),
|cx| view! { cx, <App/> }, || view! { <App/> },
) )
.service(Files::new("/", site_root)) .service(Files::new("/", site_root))
//.wrap(middleware::Compress::default()) //.wrap(middleware::Compress::default())
@ -70,9 +71,9 @@ pub fn main() {
console_error_panic_hook::set_once(); console_error_panic_hook::set_once();
leptos::mount_to_body(move |cx| { leptos::mount_to_body(move || {
// note: for testing it may be preferrable to replace this with a // note: for testing it may be preferrable to replace this with a
// more specific component, although leptos_router should still work // more specific component, although leptos_router should still work
view! {cx, <App/> } view! {<App/> }
}); });
} }

@ -12,108 +12,98 @@ use crate::components::validation_err::ValidationErr;
#[component] #[component]
pub fn CompanyEdit( pub fn CompanyEdit(
cx: Scope, company: ReadSignal<Company>,
company: ReadSignal<Option<Company>>,
opener: DialogOpener, opener: DialogOpener,
) -> impl IntoView { ) -> impl IntoView {
view! {cx, let update_company = create_server_action::<UpdateCompany>();
{move || let upd_val = update_company.value();
if let Some(c) = company.get() { let validator = Validator::new();
let update_company = create_server_action::<UpdateCompany>(cx);
let upd_val = update_company.value(); view! {
let validator = Validator::new(cx); <ActionForm
view! {cx, on:submit=move |ev| {
<ActionForm let act = UpdateCompany::from_event(&ev);
on:submit=move |ev| { if !act.is_err() {
let act = UpdateCompany::from_event(&ev); validator.check(&act.unwrap().company, &ev);
if !act.is_err() { }
validator.check(&act.unwrap().company, &ev);
}
}
action=update_company>
<ModalDialog opener=opener title="Edit company">
<ModalBody>
<ServerErr result={upd_val} opener=opener/>
<ValidationErr validator=validator />
<input type="hidden" value=c.id() name="company[id]"/>
<div class="row">
<div class="col mb-3">
<label for="nameWithTitle" class="form-label">"Name"</label>
<input
type="text"
id="nameWithTitle"
class="form-control"
placeholder="Enter Name"
value=c.name
name="company[name]"
/>
</div>
</div>
<div class="row">
<div class="col mb-3">
<label for="street" class="form-label">"Street"</label>
<input
type="text"
id="street"
class="form-control"
placeholder="Enter Street"
value=c.street
name="company[street]"
/>
</div>
<div class="col-4 mb-3">
<label for="houseNumber" class="form-label">"House number"</label>
<input
type="text"
id="houseNumber"
class="form-control"
placeholder="Enter House number"
value=c.house_number
name="company[house_number]"
/>
</div>
</div>
<div class="row">
<div class="col-4 mb-3">
<label for="zip" class="form-label">"ZIP code"</label>
<input
type="text"
id="zip"
class="form-control"
placeholder="Enter ZIP code"
value=c.zip_code
name="company[zip_code]"
/>
</div>
<div class="col mb-3">
<label for="city" class="form-label">"City"</label>
<input
type="text"
id="city"
class="form-control"
placeholder="Enter City"
value=c.city
name="company[city]"
/>
</div>
</div>
</ModalBody>
<ModalFooter>
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal" on:click=move |_| opener.hide()>
{trl(cx, "Close")}
</button>
<button type="submit" class="btn btn-primary">
{trl(cx, "Save changes")}
</button>
</ModalFooter>
</ModalDialog>
</ActionForm>
}
} else {
view! {cx,
<DlgNotLoaded opener=opener title="Edit company" />
} }
} action=update_company>
} <ModalDialog opener=opener title="Edit company">
<ModalBody>
<ServerErr result={upd_val} opener=opener/>
<ValidationErr validator=validator />
<input type="hidden" value={move || company.get().id()} name="company[id]"/>
<div class="row">
<div class="col mb-3">
<label for="nameWithTitle" class="form-label">"Name"</label>
<input
type="text"
id="nameWithTitle"
class="form-control"
placeholder="Enter Name"
value={move || company.get().name}
name="company[name]"
/>
</div>
</div>
<div class="row">
<div class="col mb-3">
<label for="street" class="form-label">"Street"</label>
<input
type="text"
id="street"
class="form-control"
placeholder="Enter Street"
value={move || company.get().street}
name="company[street]"
/>
</div>
<div class="col-4 mb-3">
<label for="houseNumber" class="form-label">"House number"</label>
<input
type="text"
id="houseNumber"
class="form-control"
placeholder="Enter House number"
value={move || company.get().house_number}
name="company[house_number]"
/>
</div>
</div>
<div class="row">
<div class="col-4 mb-3">
<label for="zip" class="form-label">"ZIP code"</label>
<input
type="text"
id="zip"
class="form-control"
placeholder="Enter ZIP code"
value={move || company.get().zip_code}
name="company[zip_code]"
/>
</div>
<div class="col mb-3">
<label for="city" class="form-label">"City"</label>
<input
type="text"
id="city"
class="form-control"
placeholder="Enter City"
value={move || company.get().city}
name="company[city]"
/>
</div>
</div>
</ModalBody>
<ModalFooter>
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal" on:click=move |_| opener.hide()>
{trl("Close")}
</button>
<button type="submit" class="btn btn-primary">
{trl("Save changes")}
</button>
</ModalFooter>
</ModalDialog>
</ActionForm>
} }
} }

@ -1,32 +1,33 @@
use leptos::*; use leptos::*;
use serde::de::Unexpected::Option; use serde::de::Unexpected::Option;
use crate::backend::company::get_company; use crate::backend::company::get_company;
use crate::backend::data::Company;
use crate::components::modal_box::DialogOpener; use crate::components::modal_box::DialogOpener;
use crate::locales::trl; use crate::locales::trl;
use crate::pages::company_edit::CompanyEdit; use crate::pages::company_edit::CompanyEdit;
#[component] #[component]
pub fn CompanyInfo(cx: Scope) -> impl IntoView { pub fn CompanyInfo() -> impl IntoView {
let editor = DialogOpener::new(cx); let editor = DialogOpener::new();
let company = create_resource(cx, move|| editor.visible(), move |_| { get_company(cx) }); let company = create_resource(move|| editor.visible(), move |_| { get_company() });
let (cmp, set_cmp) = create_signal(cx, None); let (cmp, set_cmp) = create_signal(Company::default());
view! {cx, view! {
<CompanyEdit company={cmp} opener=editor/> <CompanyEdit company={cmp} opener=editor/>
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><i class="bx bx-buildings"></i>" "{trl(cx, "Company info")}</h5> <h5 class="card-title"><i class="bx bx-buildings"></i>" "{trl("Company info")}</h5>
<p class="card-text"> <p class="card-text">
<Transition fallback=move || view! {cx, <p>{trl(cx, "Loading...")}</p> }> <Transition fallback=move || view! {<p>{trl("Loading...")}</p> }>
{move || { {move || {
company.read(cx).map(|c| match c { company.read().map(|c| match c {
Err(e) => {view! {cx, <p>{trl(cx, "Error loading data")}</p> Err(e) => {view! {<p>{trl("Error loading data")}</p>
<p>{e.to_string()}</p> <p>{e.to_string()}</p>
}} }}
Ok(c) => { Ok(c) => {
set_cmp.update(|cmp| *cmp = Some(c.clone())); set_cmp.update(|cmp| *cmp = c.clone());
view! { view! {
cx, <p><b>{c.name}</b></p> <p><b>{c.name}</b></p>
<p>{c.street}" "{c.house_number}<br/> <p>{c.street}" "{c.house_number}<br/>
{c.zip_code}" "{c.city} {c.zip_code}" "{c.city}
</p> </p>

@ -5,21 +5,21 @@ use crate::locales::trl;
/// Renders the home page of your application. /// Renders the home page of your application.
#[component] #[component]
pub fn HomePage(cx: Scope) -> impl IntoView { pub fn HomePage() -> impl IntoView {
// Creates a reactive value to update the button // Creates a reactive value to update the button
let (count, set_count) = create_signal(cx, 0); let (count, set_count) = create_signal(0);
let on_click = move |_| set_count.update(|count| *count += 1); let on_click = move |_| set_count.update(|count| *count += 1);
let dialog = DialogOpener::new(cx); let dialog = DialogOpener::new();
//let (dialog, set_dialog) = create_signal(cx, false); //let (dialog, set_dialog) = create_signal(false);
//let on_dialog = move |_| dialog.set_visible.update(|dialog| {*dialog = true}); //let on_dialog = move |_| dialog.set_visible.update(|dialog| {*dialog = true});
//let pok = use_context::<Request>(cx); //let pok = use_context::<Request>();
//log!("{:?}", pok); //log!("{:?}", pok);
view! { cx, view! {
<ModalDialog opener={dialog} title="Titulek"> <ModalDialog opener={dialog} title="Titulek">
<ModalBody> <ModalBody>
<div class="row"> <div class="row">
@ -67,14 +67,14 @@ pub fn HomePage(cx: Scope) -> impl IntoView {
<button on:click=move |_| dialog.show()>"Dialog"</button> <button on:click=move |_| dialog.show()>"Dialog"</button>
<button on:click=move |_| { <button on:click=move |_| {
spawn_local(async move { spawn_local(async move {
set_session(cx).await; set_session().await;
}); });
}>"Session"</button> }>"Session"</button>
<button on:click=move |_| { <button on:click=move |_| {
spawn_local(async move { spawn_local(async move {
get_session(cx).await; get_session().await;
}); });
}>"Session get"</button> }>"Session get"</button>
<p>{trl(cx, "testik!")}</p> <p>{trl("testik!")}</p>
} }
} }

@ -3,9 +3,9 @@ use crate::locales::trl;
use crate::pages::company_info::CompanyInfo; use crate::pages::company_info::CompanyInfo;
#[component] #[component]
pub fn Settings(cx: Scope) -> impl IntoView { pub fn Settings() -> impl IntoView {
view! {cx, view! {
<h1>{trl(cx, "Settings")}</h1> <h1>{trl("Settings")}</h1>
<div class="row mb-5"> <div class="row mb-5">
<div class="col-md-6 col-lg-4 mb-3"> <div class="col-md-6 col-lg-4 mb-3">
<CompanyInfo/> <CompanyInfo/>

@ -1,14 +1,15 @@
use leptos::*; use leptos::*;
#[server(SetSession, "/api", "Url", "set_session")] #[server(SetSession, "/api", "Url", "set_session")]
pub async fn set_session(cx: Scope) -> Result<(), ServerFnError> { pub async fn set_session() -> Result<(), ServerFnError> {
use leptos_actix::extract; use leptos_actix::extract;
use actix_session::*; use actix_session::*;
use actix_web::web::Data; use actix_web::web::Data;
use leptos::logging::log;
//use crate::DataPok; //use crate::DataPok;
extract(cx, |session: Session| async move { extract(|session: Session| async move {
leptos::log!("extract"); log!("extract");
let pok = session.insert("user", "uzivatel"); let pok = session.insert("user", "uzivatel");
log!("{pok:?}"); log!("{pok:?}");
}).await }).await
@ -17,12 +18,13 @@ pub async fn set_session(cx: Scope) -> Result<(), ServerFnError> {
} }
#[server(GetSession, "/api")] #[server(GetSession, "/api")]
pub async fn get_session(cx: Scope) -> Result<(), ServerFnError> { pub async fn get_session() -> Result<(), ServerFnError> {
use leptos_actix::extract; use leptos_actix::extract;
use actix_session::*; use actix_session::*;
use leptos::logging::log;
extract(cx, |session: Session| async move { extract(|session: Session| async move {
leptos::log!("extract"); log!("extract");
let pok = session.get::<String>("user"); let pok = session.get::<String>("user");
log!("{pok:?}"); log!("{pok:?}");
}).await }).await

@ -12,10 +12,10 @@ pub struct Validator {
} }
impl Validator { impl Validator {
pub fn new(cx: Scope) -> Self { pub fn new() -> Self {
let (valid, set_valid) = create_signal(cx, true); let (valid, set_valid) = create_signal(true);
let (message, set_message) = create_signal(cx, None); let (message, set_message) = create_signal(None);
let (messages, set_messages) = create_signal(cx, None); let (messages, set_messages) = create_signal(None);
Self { Self {
message, message,
set_message, set_message,

Loading…
Cancel
Save