From 9bc48ff63d8a46edfe4f737a5fc064b00d658323 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Mon, 2 Sep 2024 23:20:37 +0200 Subject: [PATCH] add router --- .gitignore | 1 + Cargo.lock | 2 + Cargo.toml | 6 +- README.md | 14 +++- index.html | 7 -- rust-toolchain.toml | 2 - src/app.rs | 154 +++++++------------------------------------- src/lib.rs | 9 ++- src/main.rs | 36 ++++++----- src/values.rs | 118 +++++++++++++++++++++++++++++++++ 10 files changed, 190 insertions(+), 159 deletions(-) delete mode 100644 index.html delete mode 100644 rust-toolchain.toml create mode 100644 src/values.rs diff --git a/.gitignore b/.gitignore index 526a9a9..78ccf8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Todos.db target/ +style/output.css diff --git a/Cargo.lock b/Cargo.lock index cb32f8e..2a7b4ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2452,6 +2452,8 @@ dependencies = [ "gloo", "leptos", "leptos_actix", + "leptos_meta", + "leptos_router", "log", "serde", "server_fn 0.6.14", diff --git a/Cargo.toml b/Cargo.toml index dfbdeb9..b6facf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ console_error_panic_hook = "0.1.7" serde = { version = "1.0", features = ["derive"] } futures = "0.3.30" leptos = { git = "https://github.com/leptos-rs/leptos" } +leptos_router = { git = "https://github.com/leptos-rs/leptos" } +leptos_meta = { git = "https://github.com/leptos-rs/leptos" } leptos_actix = { git = "https://github.com/leptos-rs/leptos", optional = true } log = "0.4.22" simple_logger = "5.0" @@ -36,6 +38,8 @@ ssr = [ "dep:sqlx", "leptos/ssr", "leptos_actix", + "leptos_meta/ssr", + "leptos_router/ssr", "dep:tokio", ] @@ -52,7 +56,7 @@ site-root = "target/site" # Defaults to pkg site-pkg-dir = "pkg" # [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to //app.css -style-file = "./style.css" +style-file = "style/output.css" # [Optional] Files in the asset-dir will be copied to the site-root directory assets-dir = "public" # The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup. diff --git a/README.md b/README.md index 9aa4130..fa32471 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,16 @@ source : https://github.com/Oishh/leptos-axum-tailwind-start wasm-pack build --target=web --debug --no-default-features --features=hydrate cargo run --no-default-features --features=ssr -npx tailwindcss -i ./input.css -o ./style/output.css --watch +npx tailwindcss -i ./input.css -o ./pkg/output.css --watch + +## features +[x] ssr +[ ] MySQL +[x] tailwindcss +[x] router +[ ] deploy + +## pages +[ ] liens +[ ] formulaire +[ ] recap capteurs diff --git a/index.html b/index.html deleted file mode 100644 index b63cea8..0000000 --- a/index.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - -
- - diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index ff2a4ff..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "stable" # test change diff --git a/src/app.rs b/src/app.rs index f137bb1..d058e36 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,157 +1,47 @@ -use cfg_if::cfg_if; -use leptos::*; +use crate::values::FormValues; +use crate::todo::TodoApp; +use leptos::prelude::*; use leptos_meta::*; -use leptos_router::*; -use serde::{Deserialize, Serialize}; - -pub struct Option { - value: &'static str, - name: &'static str, - topic: &'static str, -} - -pub const OPTIONS: &[Option] = &[ - Option { - value: "citerne", - name: "Citerne", - topic: "home/citerne/height", - }, - Option { - value: "eau", - name: "Eau", - topic: "home/eau/volume", - }, - Option { - value: "elec-hight", - name: "Electricité heure pleine", - topic: "home/elec-hight/pleine", - }, - Option { - value: "elec-low", - name: "Electricité heure creuse", - topic: "home/elec-low/creuse", - }, -]; - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct Value { - id: u16, - service: String, - capteur: String, - type_donnee: String, - donnee: String, -} - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] -struct HeftyData { - capteur: String, - value: String, -} - -#[cfg(feature = "ssr")] -pub mod ssr { - // use http::{header::SET_COOKIE, HeaderMap, HeaderValue, StatusCode}; - use leptos::server_fn::ServerFnError; - use sqlx::{Connection, SqliteConnection}; - - pub async fn db() -> Result { - Ok(SqliteConnection::connect("sqlite:Todos.db").await?) - } -} +use leptos_router::{ + components::{FlatRoutes, Route, Router}, + ParamSegment, SsrMode, StaticSegment, +}; #[component] pub fn App() -> impl IntoView { + // Provides context that manages stylesheets, titles, meta tags, etc. provide_meta_context(); + let fallback = || view! { "Page not found." }.into_view(); view! { - - - -