From 6dbf5b5438edffeb7b21c96a192bdde86c68acfc Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Mon, 19 Aug 2024 19:34:12 +0200 Subject: [PATCH 01/12] feat: Add HX-Request header extraction to CPS endpoint --- crates/app/src/pages/cps.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/app/src/pages/cps.rs b/crates/app/src/pages/cps.rs index bee64c5..7927e7b 100644 --- a/crates/app/src/pages/cps.rs +++ b/crates/app/src/pages/cps.rs @@ -1,9 +1,34 @@ use askama_axum::Template; +use axum::{ + async_trait, + extract::FromRequestParts, + http::{request::Parts, HeaderMap, StatusCode}, +}; #[derive(Template)] #[template(path = "pages/cps.html")] pub struct CpsTemplate; -pub async fn cps() -> CpsTemplate { +pub struct ExtractHxRequest(bool); + +#[async_trait] +impl FromRequestParts for ExtractHxRequest +where + S: Send + Sync, +{ + type Rejection = (StatusCode, &'static str); + + async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result { + if parts.headers.get("HX-Request").is_some() { + Ok(ExtractHxRequest(true)) + } else { + Ok(ExtractHxRequest(false)) + } + } +} + +pub async fn cps(headers: HeaderMap, hx_request: ExtractHxRequest) -> CpsTemplate { + println!("{:#?}", headers); + println!("{:#?}", hx_request.0); CpsTemplate } From 217667253ad253ccc5d5b6519cb3c25aff5773c7 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Mon, 19 Aug 2024 19:34:34 +0200 Subject: [PATCH 02/12] feat: Add hx-push-url attribute to nav menu item --- crates/app/templates/layout/nav/nav-menu-items.html | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/app/templates/layout/nav/nav-menu-items.html b/crates/app/templates/layout/nav/nav-menu-items.html index 9320312..f9de594 100644 --- a/crates/app/templates/layout/nav/nav-menu-items.html +++ b/crates/app/templates/layout/nav/nav-menu-items.html @@ -5,6 +5,7 @@ hx-trigger="click" hx-target="#main-container" hx-swap="innerHTML" + hx-push-url="true" class="{{ Self::get_classes(self, item.current) }}" aria-current="{% if item.current %}page{% endif %}" > From 7487b34a1759889e41078e903dd9d65916dca75b Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Fri, 23 Aug 2024 15:41:49 +0200 Subject: [PATCH 03/12] refacto: rename html and rs templates dirs to old_* --- crates/app/{templates => old_templates}/base.html | 0 crates/app/{templates => old_templates}/hello.html | 0 crates/app/{templates => old_templates}/index.html | 0 crates/app/{templates => old_templates}/layout/nav.html | 0 .../layout/nav/desktop/menu-items.html | 0 .../layout/nav/desktop/notifications-button.html | 0 .../layout/nav/desktop/profile-dropdown.html | 0 .../layout/nav/desktop/profile.html | 0 .../app/{templates => old_templates}/layout/nav/logo.html | 0 .../layout/nav/mobile/menu-button.html | 0 .../layout/nav/mobile/menu-items.html | 0 .../layout/nav/mobile/notifications-button.html | 0 .../layout/nav/mobile/profile-items.html | 0 .../layout/nav/mobile/profile.html | 0 .../layout/nav/nav-menu-items.html | 0 .../layout/nav/notifications-icon.html | 0 .../layout/nav/profile-menu-items.html | 0 crates/app/{templates => old_templates}/pages/cps.html | 0 crates/app/{templates => old_templates}/pages/home.html | 0 .../app/{templates => src/components}/skeletons/card.html | 0 .../components}/skeletons/menu-items.html | 0 .../components}/skeletons/page-title.html | 0 crates/app/src/lib.rs | 7 ++----- crates/app/src/main.rs | 8 +++++--- crates/app/src/{pages => old_pages}/cps.rs | 0 crates/app/src/{pages => old_pages}/home.rs | 0 crates/app/src/{pages => old_pages}/mod.rs | 0 crates/app/src/{templates => old_templates}/hello.rs | 0 crates/app/src/{templates => old_templates}/mod.rs | 0 crates/app/src/{templates => old_templates}/nav.rs | 0 crates/app/src/{templates => old_templates}/profile.rs | 0 31 files changed, 7 insertions(+), 8 deletions(-) rename crates/app/{templates => old_templates}/base.html (100%) rename crates/app/{templates => old_templates}/hello.html (100%) rename crates/app/{templates => old_templates}/index.html (100%) rename crates/app/{templates => old_templates}/layout/nav.html (100%) rename crates/app/{templates => old_templates}/layout/nav/desktop/menu-items.html (100%) rename crates/app/{templates => old_templates}/layout/nav/desktop/notifications-button.html (100%) rename crates/app/{templates => old_templates}/layout/nav/desktop/profile-dropdown.html (100%) rename crates/app/{templates => old_templates}/layout/nav/desktop/profile.html (100%) rename crates/app/{templates => old_templates}/layout/nav/logo.html (100%) rename crates/app/{templates => old_templates}/layout/nav/mobile/menu-button.html (100%) rename crates/app/{templates => old_templates}/layout/nav/mobile/menu-items.html (100%) rename crates/app/{templates => old_templates}/layout/nav/mobile/notifications-button.html (100%) rename crates/app/{templates => old_templates}/layout/nav/mobile/profile-items.html (100%) rename crates/app/{templates => old_templates}/layout/nav/mobile/profile.html (100%) rename crates/app/{templates => old_templates}/layout/nav/nav-menu-items.html (100%) rename crates/app/{templates => old_templates}/layout/nav/notifications-icon.html (100%) rename crates/app/{templates => old_templates}/layout/nav/profile-menu-items.html (100%) rename crates/app/{templates => old_templates}/pages/cps.html (100%) rename crates/app/{templates => old_templates}/pages/home.html (100%) rename crates/app/{templates => src/components}/skeletons/card.html (100%) rename crates/app/{templates => src/components}/skeletons/menu-items.html (100%) rename crates/app/{templates => src/components}/skeletons/page-title.html (100%) rename crates/app/src/{pages => old_pages}/cps.rs (100%) rename crates/app/src/{pages => old_pages}/home.rs (100%) rename crates/app/src/{pages => old_pages}/mod.rs (100%) rename crates/app/src/{templates => old_templates}/hello.rs (100%) rename crates/app/src/{templates => old_templates}/mod.rs (100%) rename crates/app/src/{templates => old_templates}/nav.rs (100%) rename crates/app/src/{templates => old_templates}/profile.rs (100%) diff --git a/crates/app/templates/base.html b/crates/app/old_templates/base.html similarity index 100% rename from crates/app/templates/base.html rename to crates/app/old_templates/base.html diff --git a/crates/app/templates/hello.html b/crates/app/old_templates/hello.html similarity index 100% rename from crates/app/templates/hello.html rename to crates/app/old_templates/hello.html diff --git a/crates/app/templates/index.html b/crates/app/old_templates/index.html similarity index 100% rename from crates/app/templates/index.html rename to crates/app/old_templates/index.html diff --git a/crates/app/templates/layout/nav.html b/crates/app/old_templates/layout/nav.html similarity index 100% rename from crates/app/templates/layout/nav.html rename to crates/app/old_templates/layout/nav.html diff --git a/crates/app/templates/layout/nav/desktop/menu-items.html b/crates/app/old_templates/layout/nav/desktop/menu-items.html similarity index 100% rename from crates/app/templates/layout/nav/desktop/menu-items.html rename to crates/app/old_templates/layout/nav/desktop/menu-items.html diff --git a/crates/app/templates/layout/nav/desktop/notifications-button.html b/crates/app/old_templates/layout/nav/desktop/notifications-button.html similarity index 100% rename from crates/app/templates/layout/nav/desktop/notifications-button.html rename to crates/app/old_templates/layout/nav/desktop/notifications-button.html diff --git a/crates/app/templates/layout/nav/desktop/profile-dropdown.html b/crates/app/old_templates/layout/nav/desktop/profile-dropdown.html similarity index 100% rename from crates/app/templates/layout/nav/desktop/profile-dropdown.html rename to crates/app/old_templates/layout/nav/desktop/profile-dropdown.html diff --git a/crates/app/templates/layout/nav/desktop/profile.html b/crates/app/old_templates/layout/nav/desktop/profile.html similarity index 100% rename from crates/app/templates/layout/nav/desktop/profile.html rename to crates/app/old_templates/layout/nav/desktop/profile.html diff --git a/crates/app/templates/layout/nav/logo.html b/crates/app/old_templates/layout/nav/logo.html similarity index 100% rename from crates/app/templates/layout/nav/logo.html rename to crates/app/old_templates/layout/nav/logo.html diff --git a/crates/app/templates/layout/nav/mobile/menu-button.html b/crates/app/old_templates/layout/nav/mobile/menu-button.html similarity index 100% rename from crates/app/templates/layout/nav/mobile/menu-button.html rename to crates/app/old_templates/layout/nav/mobile/menu-button.html diff --git a/crates/app/templates/layout/nav/mobile/menu-items.html b/crates/app/old_templates/layout/nav/mobile/menu-items.html similarity index 100% rename from crates/app/templates/layout/nav/mobile/menu-items.html rename to crates/app/old_templates/layout/nav/mobile/menu-items.html diff --git a/crates/app/templates/layout/nav/mobile/notifications-button.html b/crates/app/old_templates/layout/nav/mobile/notifications-button.html similarity index 100% rename from crates/app/templates/layout/nav/mobile/notifications-button.html rename to crates/app/old_templates/layout/nav/mobile/notifications-button.html diff --git a/crates/app/templates/layout/nav/mobile/profile-items.html b/crates/app/old_templates/layout/nav/mobile/profile-items.html similarity index 100% rename from crates/app/templates/layout/nav/mobile/profile-items.html rename to crates/app/old_templates/layout/nav/mobile/profile-items.html diff --git a/crates/app/templates/layout/nav/mobile/profile.html b/crates/app/old_templates/layout/nav/mobile/profile.html similarity index 100% rename from crates/app/templates/layout/nav/mobile/profile.html rename to crates/app/old_templates/layout/nav/mobile/profile.html diff --git a/crates/app/templates/layout/nav/nav-menu-items.html b/crates/app/old_templates/layout/nav/nav-menu-items.html similarity index 100% rename from crates/app/templates/layout/nav/nav-menu-items.html rename to crates/app/old_templates/layout/nav/nav-menu-items.html diff --git a/crates/app/templates/layout/nav/notifications-icon.html b/crates/app/old_templates/layout/nav/notifications-icon.html similarity index 100% rename from crates/app/templates/layout/nav/notifications-icon.html rename to crates/app/old_templates/layout/nav/notifications-icon.html diff --git a/crates/app/templates/layout/nav/profile-menu-items.html b/crates/app/old_templates/layout/nav/profile-menu-items.html similarity index 100% rename from crates/app/templates/layout/nav/profile-menu-items.html rename to crates/app/old_templates/layout/nav/profile-menu-items.html diff --git a/crates/app/templates/pages/cps.html b/crates/app/old_templates/pages/cps.html similarity index 100% rename from crates/app/templates/pages/cps.html rename to crates/app/old_templates/pages/cps.html diff --git a/crates/app/templates/pages/home.html b/crates/app/old_templates/pages/home.html similarity index 100% rename from crates/app/templates/pages/home.html rename to crates/app/old_templates/pages/home.html diff --git a/crates/app/templates/skeletons/card.html b/crates/app/src/components/skeletons/card.html similarity index 100% rename from crates/app/templates/skeletons/card.html rename to crates/app/src/components/skeletons/card.html diff --git a/crates/app/templates/skeletons/menu-items.html b/crates/app/src/components/skeletons/menu-items.html similarity index 100% rename from crates/app/templates/skeletons/menu-items.html rename to crates/app/src/components/skeletons/menu-items.html diff --git a/crates/app/templates/skeletons/page-title.html b/crates/app/src/components/skeletons/page-title.html similarity index 100% rename from crates/app/templates/skeletons/page-title.html rename to crates/app/src/components/skeletons/page-title.html diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index 8bdad03..e84842f 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -1,6 +1,3 @@ -mod pages; -mod templates; - use std::path::Path; use askama_axum::Template; @@ -23,7 +20,7 @@ pub fn get_router(assets_path: &Path) -> axum::Router { axum::Router::new() .nest_service("/assets", ServeDir::new(assets_path)) .route("/", axum::routing::get(root)) - .nest("/pages", pages::get_routes()) - .merge(templates::get_routes()) + // .nest("/pages", old_pages::get_routes()) + // .merge(old_templates::get_routes()) .fallback(fallback) } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 98f0882..ebd3b56 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1,15 +1,17 @@ -use ::app::get_router; +use std::path::Path; +use std::{env, io}; + use axum::body::Body; use axum::http::Request; use listenfd::ListenFd; use notify::Watcher; -use std::path::Path; -use std::{env, io}; use thiserror::Error; use tokio::net::TcpListener; use tower_livereload::predicate::Predicate; use tower_livereload::LiveReloadLayer; +use ::app::get_router; + #[derive(Error, Debug)] pub enum AppError { #[error("Unable to bind to TCP listener")] diff --git a/crates/app/src/pages/cps.rs b/crates/app/src/old_pages/cps.rs similarity index 100% rename from crates/app/src/pages/cps.rs rename to crates/app/src/old_pages/cps.rs diff --git a/crates/app/src/pages/home.rs b/crates/app/src/old_pages/home.rs similarity index 100% rename from crates/app/src/pages/home.rs rename to crates/app/src/old_pages/home.rs diff --git a/crates/app/src/pages/mod.rs b/crates/app/src/old_pages/mod.rs similarity index 100% rename from crates/app/src/pages/mod.rs rename to crates/app/src/old_pages/mod.rs diff --git a/crates/app/src/templates/hello.rs b/crates/app/src/old_templates/hello.rs similarity index 100% rename from crates/app/src/templates/hello.rs rename to crates/app/src/old_templates/hello.rs diff --git a/crates/app/src/templates/mod.rs b/crates/app/src/old_templates/mod.rs similarity index 100% rename from crates/app/src/templates/mod.rs rename to crates/app/src/old_templates/mod.rs diff --git a/crates/app/src/templates/nav.rs b/crates/app/src/old_templates/nav.rs similarity index 100% rename from crates/app/src/templates/nav.rs rename to crates/app/src/old_templates/nav.rs diff --git a/crates/app/src/templates/profile.rs b/crates/app/src/old_templates/profile.rs similarity index 100% rename from crates/app/src/templates/profile.rs rename to crates/app/src/old_templates/profile.rs From 8ce18e53d5eaed85358da5abae0f321fedb2f73f Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Fri, 23 Aug 2024 18:45:43 +0200 Subject: [PATCH 04/12] feat: Rewrite routes, pages and components to be more HATEOAS --- crates/app/askama.toml | 6 +++ crates/app/old_templates/index.html | 34 ------------- .../components}/base.html | 6 +-- .../app/src/components/navbar/menu-item.html | 14 ++++++ crates/app/src/components/navbar/navbar.html | 50 +++++++++++++++++++ crates/app/src/lib.rs | 6 ++- crates/app/src/main.rs | 15 ++++-- crates/app/src/menu.rs | 20 ++++++++ crates/app/src/old_pages/mod.rs | 10 ---- crates/app/src/pages/cps.html | 44 ++++++++++++++++ crates/app/src/{old_pages => pages}/cps.rs | 2 +- crates/app/src/pages/index.html | 44 ++++++++++++++++ crates/app/src/pages/mod.rs | 7 +++ 13 files changed, 201 insertions(+), 57 deletions(-) create mode 100644 crates/app/askama.toml delete mode 100644 crates/app/old_templates/index.html rename crates/app/{old_templates => src/components}/base.html (82%) create mode 100644 crates/app/src/components/navbar/menu-item.html create mode 100644 crates/app/src/components/navbar/navbar.html create mode 100644 crates/app/src/menu.rs delete mode 100644 crates/app/src/old_pages/mod.rs create mode 100644 crates/app/src/pages/cps.html rename crates/app/src/{old_pages => pages}/cps.rs (95%) create mode 100644 crates/app/src/pages/index.html create mode 100644 crates/app/src/pages/mod.rs diff --git a/crates/app/askama.toml b/crates/app/askama.toml new file mode 100644 index 0000000..e00fe7b --- /dev/null +++ b/crates/app/askama.toml @@ -0,0 +1,6 @@ +[general] +# Directories to search for templates, relative to the crate root. +dirs = [ + "src/pages", + "src/components", +] diff --git a/crates/app/old_templates/index.html b/crates/app/old_templates/index.html deleted file mode 100644 index 9d69e52..0000000 --- a/crates/app/old_templates/index.html +++ /dev/null @@ -1,34 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Pharma Libre{% endblock %} - -{% block body %} -
-
-
-

- {% include "skeletons/page-title.html" %} -

-
-
-
-
- -
- {% include "skeletons/card.html" %} -
-
-
-
-{% endblock %} diff --git a/crates/app/old_templates/base.html b/crates/app/src/components/base.html similarity index 82% rename from crates/app/old_templates/base.html rename to crates/app/src/components/base.html index 3013631..651fb67 100644 --- a/crates/app/old_templates/base.html +++ b/crates/app/src/components/base.html @@ -9,14 +9,10 @@ - {% block head %}{% endblock %} + {% block headx %}{% endblock %}
- {% block nav %} - {% include "layout/nav.html" %} - {% endblock %} - {% block body %}{% endblock %}
diff --git a/crates/app/src/components/navbar/menu-item.html b/crates/app/src/components/navbar/menu-item.html new file mode 100644 index 0000000..b002e0c --- /dev/null +++ b/crates/app/src/components/navbar/menu-item.html @@ -0,0 +1,14 @@ +{% set selected = item.id == current %} +
  • + + {{ item.label }} + +
  • diff --git a/crates/app/src/components/navbar/navbar.html b/crates/app/src/components/navbar/navbar.html new file mode 100644 index 0000000..24a8af6 --- /dev/null +++ b/crates/app/src/components/navbar/navbar.html @@ -0,0 +1,50 @@ +{% macro navbar(current) %} + +{% let items=crate::menu::get_menu_items() %} + + +{% endmacro %} diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index e84842f..29c75dc 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -4,6 +4,9 @@ use askama_axum::Template; use axum::http::{StatusCode, Uri}; use tower_http::services::ServeDir; +mod menu; +mod pages; + async fn fallback(uri: Uri) -> (StatusCode, String) { (StatusCode::NOT_FOUND, format!("No route for {uri}")) } @@ -20,7 +23,6 @@ pub fn get_router(assets_path: &Path) -> axum::Router { axum::Router::new() .nest_service("/assets", ServeDir::new(assets_path)) .route("/", axum::routing::get(root)) - // .nest("/pages", old_pages::get_routes()) - // .merge(old_templates::get_routes()) + .merge(pages::get_routes()) .fallback(fallback) } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index ebd3b56..67f59ab 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1,4 +1,4 @@ -use std::path::Path; +use std::path::{Path, PathBuf}; use std::{env, io}; use axum::body::Body; @@ -48,12 +48,14 @@ async fn get_tcp_listener() -> Result { } fn get_livereload_layer( - templates_path: &Path, + templates_paths: Vec, ) -> Result, notify::Error> { let livereload = LiveReloadLayer::new(); let reloader = livereload.reloader(); let mut watcher = notify::recommended_watcher(move |_| reloader.reload())?; - watcher.watch(templates_path, notify::RecursiveMode::Recursive)?; + for templates_path in templates_paths { + watcher.watch(templates_path.as_path(), notify::RecursiveMode::Recursive)?; + } Ok(livereload.request_predicate::(NotHtmxPredicate)) } @@ -63,10 +65,13 @@ async fn main() -> Result<(), AppError> { var: "CARGO_MANIFEST_DIR", })?; let assets_path = Path::new(&manifest_dir).join("assets"); - let templates_path = Path::new(&manifest_dir).join("templates"); + let templates_paths = vec![ + Path::new(&manifest_dir).join("src/pages"), + Path::new(&manifest_dir).join("src/components"), + ]; let livereload_layer = - get_livereload_layer(&templates_path).map_err(AppError::NotifyWatcher)?; + get_livereload_layer(templates_paths).map_err(AppError::NotifyWatcher)?; let router = get_router(assets_path.as_path()).layer(livereload_layer); let listener: TcpListener = get_tcp_listener().await.map_err(AppError::TCPListener)?; diff --git a/crates/app/src/menu.rs b/crates/app/src/menu.rs new file mode 100644 index 0000000..a3d51ac --- /dev/null +++ b/crates/app/src/menu.rs @@ -0,0 +1,20 @@ +pub struct MenuItem { + pub id: String, + pub label: String, + pub href: String, +} + +pub fn get_menu_items() -> Vec { + vec![ + MenuItem { + id: "home".to_string(), + label: "Accueil".to_string(), + href: "/".to_string(), + }, + MenuItem { + id: "cps".to_string(), + label: "CPS".to_string(), + href: "/cps".to_string(), + }, + ] +} diff --git a/crates/app/src/old_pages/mod.rs b/crates/app/src/old_pages/mod.rs deleted file mode 100644 index 0580595..0000000 --- a/crates/app/src/old_pages/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -use axum::{routing, Router}; - -mod cps; -mod home; - -pub fn get_routes() -> Router { - Router::new() - .route("/home", routing::get(home::home)) - .route("/cps", routing::get(cps::cps)) -} diff --git a/crates/app/src/pages/cps.html b/crates/app/src/pages/cps.html new file mode 100644 index 0000000..52b6e99 --- /dev/null +++ b/crates/app/src/pages/cps.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} +{% import "navbar/navbar.html" as navbar -%} + +{% block title %}Pharma Libre - CPS{% endblock %} + +{% block body %} +{% call navbar::navbar(current="cps") %} +
    +
    +
    +

    + CPS +

    +
    +
    +
    +
    +
    +
    A
    +
    B
    +
    C
    +
    D
    +
    +
    E
    +
    +
    +
    +{% endblock %} diff --git a/crates/app/src/old_pages/cps.rs b/crates/app/src/pages/cps.rs similarity index 95% rename from crates/app/src/old_pages/cps.rs rename to crates/app/src/pages/cps.rs index 7927e7b..67c1de4 100644 --- a/crates/app/src/old_pages/cps.rs +++ b/crates/app/src/pages/cps.rs @@ -6,7 +6,7 @@ use axum::{ }; #[derive(Template)] -#[template(path = "pages/cps.html")] +#[template(path = "cps.html")] pub struct CpsTemplate; pub struct ExtractHxRequest(bool); diff --git a/crates/app/src/pages/index.html b/crates/app/src/pages/index.html new file mode 100644 index 0000000..58f0599 --- /dev/null +++ b/crates/app/src/pages/index.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} +{% import "navbar/navbar.html" as navbar -%} + +{% block title %}Pharma Libre - Accueil{% endblock %} + +{% block body %} +{% call navbar::navbar(current="home") %} +
    +
    +
    +

    + Accueil +

    +
    +
    +
    +
    +
    +
    A
    +
    B
    +
    C
    +
    D
    +
    +
    E
    +
    +
    +
    +{% endblock %} diff --git a/crates/app/src/pages/mod.rs b/crates/app/src/pages/mod.rs new file mode 100644 index 0000000..2c52f70 --- /dev/null +++ b/crates/app/src/pages/mod.rs @@ -0,0 +1,7 @@ +use axum::{routing, Router}; + +mod cps; + +pub fn get_routes() -> Router { + Router::new().route("/cps", routing::get(cps::cps)) +} From 3e9e8ecacc5468aa0f4daa1b864209fd3c429add Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Fri, 23 Aug 2024 18:48:12 +0200 Subject: [PATCH 05/12] chore: update style.css --- crates/app/assets/css/style.css | 531 ++++++++++++++++++-------------- crates/app/tailwind.config.js | 2 +- 2 files changed, 302 insertions(+), 231 deletions(-) diff --git a/crates/app/assets/css/style.css b/crates/app/assets/css/style.css index 94031fb..d3db34e 100644 --- a/crates/app/assets/css/style.css +++ b/crates/app/assets/css/style.css @@ -566,28 +566,8 @@ video { border-width: 0; } -.absolute { - position: absolute; -} - -.relative { - position: relative; -} - -.-inset-0\.5 { - inset: -0.125rem; -} - -.-inset-1\.5 { - inset: -0.375rem; -} - -.right-0 { - right: 0px; -} - -.z-10 { - z-index: 10; +.z-50 { + z-index: 50; } .mx-auto { @@ -595,36 +575,9 @@ video { margin-right: auto; } -.-mr-2 { - margin-right: -0.5rem; -} - -.ml-3 { - margin-left: 0.75rem; -} - -.ml-auto { - margin-left: auto; -} - -.mt-2 { - margin-top: 0.5rem; -} - -.mt-3 { - margin-top: 0.75rem; -} - -.mb-4 { - margin-bottom: 1rem; -} - -.mt-4 { +.my-4 { margin-top: 1rem; -} - -.mt-6 { - margin-top: 1.5rem; + margin-bottom: 1rem; } .mb-2 { @@ -635,10 +588,22 @@ video { margin-bottom: 0.625rem; } +.mb-4 { + margin-bottom: 1rem; +} + .me-3 { margin-inline-end: 0.75rem; } +.mt-3 { + margin-top: 0.75rem; +} + +.mt-4 { + margin-top: 1rem; +} + .block { display: block; } @@ -663,52 +628,44 @@ video { height: 2.5rem; } -.h-16 { - height: 4rem; -} - -.h-6 { - height: 1.5rem; -} - -.h-8 { - height: 2rem; -} - -.h-full { - height: 100%; -} - -.h-32 { - height: 8rem; -} - -.h-48 { - height: 12rem; -} - -.h-96 { - height: 24rem; +.h-2 { + height: 0.5rem; } .h-2\.5 { height: 0.625rem; } -.h-9 { - height: 2.25rem; +.h-32 { + height: 8rem; +} + +.h-4 { + height: 1rem; +} + +.h-48 { + height: 12rem; +} + +.h-5 { + height: 1.25rem; } .h-7 { height: 1.75rem; } -.h-2 { - height: 0.5rem; +.h-8 { + height: 2rem; } -.h-4 { - height: 1rem; +.h-96 { + height: 24rem; +} + +.h-full { + height: 100%; } .min-h-full { @@ -719,58 +676,38 @@ video { width: 2.5rem; } +.w-32 { + width: 8rem; +} + .w-48 { width: 12rem; } -.w-6 { - width: 1.5rem; +.w-5 { + width: 1.25rem; } .w-8 { width: 2rem; } -.w-auto { - width: auto; -} - -.w-32 { - width: 8rem; -} - -.w-20 { - width: 5rem; -} - -.w-24 { - width: 6rem; -} - -.w-28 { - width: 7rem; +.w-full { + width: 100%; } .max-w-7xl { max-width: 80rem; } -.max-w-xs { - max-width: 20rem; +.max-w-screen-xl { + max-width: 1280px; } .max-w-sm { max-width: 24rem; } -.flex-shrink-0 { - flex-shrink: 0; -} - -.origin-top-right { - transform-origin: top right; -} - @keyframes pulse { 50% { opacity: .5; @@ -781,12 +718,20 @@ video { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; } +.list-none { + list-style-type: none; +} + .grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); } -.grid-cols-2 { - grid-template-columns: repeat(2, minmax(0, 1fr)); +.flex-col { + flex-direction: column; +} + +.flex-wrap { + flex-wrap: wrap; } .items-center { @@ -805,48 +750,66 @@ video { gap: 1rem; } -.space-y-1 > :not([hidden]) ~ :not([hidden]) { - --tw-space-y-reverse: 0; - margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse))); - margin-bottom: calc(0.25rem * var(--tw-space-y-reverse)); +.space-x-3 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(0.75rem * var(--tw-space-x-reverse)); + margin-left: calc(0.75rem * calc(1 - var(--tw-space-x-reverse))); } -.rounded-full { - border-radius: 9999px; +.divide-y > :not([hidden]) ~ :not([hidden]) { + --tw-divide-y-reverse: 0; + border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse))); + border-bottom-width: calc(1px * var(--tw-divide-y-reverse)); } -.rounded-md { - border-radius: 0.375rem; +.divide-gray-100 > :not([hidden]) ~ :not([hidden]) { + --tw-divide-opacity: 1; + border-color: rgb(243 244 246 / var(--tw-divide-opacity)); } -.rounded-lg { - border-radius: 0.5rem; +.self-center { + align-self: center; +} + +.truncate { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.whitespace-nowrap { + white-space: nowrap; } .rounded { border-radius: 0.25rem; } -.border-2 { - border-width: 2px; +.rounded-full { + border-radius: 9999px; +} + +.rounded-lg { + border-radius: 0.5rem; } .border { border-width: 1px; } -.border-b { - border-bottom-width: 1px; -} - -.border-t { - border-top-width: 1px; +.border-2 { + border-width: 2px; } .border-dashed { border-style: dashed; } +.border-gray-100 { + --tw-border-opacity: 1; + border-color: rgb(243 244 246 / var(--tw-border-opacity)); +} + .border-gray-200 { --tw-border-opacity: 1; border-color: rgb(229 231 235 / var(--tw-border-opacity)); @@ -857,9 +820,9 @@ video { border-color: rgb(209 213 219 / var(--tw-border-opacity)); } -.bg-white { +.bg-blue-700 { --tw-bg-opacity: 1; - background-color: rgb(255 255 255 / var(--tw-bg-opacity)); + background-color: rgb(29 78 216 / var(--tw-bg-opacity)); } .bg-gray-200 { @@ -872,8 +835,19 @@ video { background-color: rgb(209 213 219 / var(--tw-bg-opacity)); } -.p-1 { - padding: 0.25rem; +.bg-gray-50 { + --tw-bg-opacity: 1; + background-color: rgb(249 250 251 / var(--tw-bg-opacity)); +} + +.bg-gray-800 { + --tw-bg-opacity: 1; + background-color: rgb(31 41 55 / var(--tw-bg-opacity)); +} + +.bg-white { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); } .p-2 { @@ -884,36 +858,39 @@ video { padding: 1rem; } +.px-3 { + padding-left: 0.75rem; + padding-right: 0.75rem; +} + .px-4 { padding-left: 1rem; padding-right: 1rem; } -.py-1 { - padding-top: 0.25rem; - padding-bottom: 0.25rem; -} - .py-10 { padding-top: 2.5rem; padding-bottom: 2.5rem; } +.py-2 { + padding-top: 0.5rem; + padding-bottom: 0.5rem; +} + +.py-3 { + padding-top: 0.75rem; + padding-bottom: 0.75rem; +} + .py-8 { padding-top: 2rem; padding-bottom: 2rem; } -.pb-3 { - padding-bottom: 0.75rem; -} - -.pt-2 { - padding-top: 0.5rem; -} - -.pt-4 { - padding-top: 1rem; +.text-2xl { + font-size: 1.5rem; + line-height: 2rem; } .text-3xl { @@ -939,6 +916,10 @@ video { font-weight: 500; } +.font-semibold { + font-weight: 600; +} + .leading-tight { line-height: 1.25; } @@ -947,9 +928,9 @@ video { letter-spacing: -0.025em; } -.text-gray-400 { +.text-gray-200 { --tw-text-opacity: 1; - color: rgb(156 163 175 / var(--tw-text-opacity)); + color: rgb(229 231 235 / var(--tw-text-opacity)); } .text-gray-500 { @@ -957,9 +938,9 @@ video { color: rgb(107 114 128 / var(--tw-text-opacity)); } -.text-gray-800 { +.text-gray-700 { --tw-text-opacity: 1; - color: rgb(31 41 55 / var(--tw-text-opacity)); + color: rgb(55 65 81 / var(--tw-text-opacity)); } .text-gray-900 { @@ -967,19 +948,9 @@ video { color: rgb(17 24 39 / var(--tw-text-opacity)); } -.text-gray-200 { +.text-white { --tw-text-opacity: 1; - color: rgb(229 231 235 / var(--tw-text-opacity)); -} - -.opacity-0 { - opacity: 0; -} - -.shadow-lg { - --tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); - --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color); - box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); + color: rgb(255 255 255 / var(--tw-text-opacity)); } .shadow { @@ -988,31 +959,11 @@ video { box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); } -.ring-1 { - --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); - --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color); - box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); -} - -.ring-black { - --tw-ring-opacity: 1; - --tw-ring-color: rgb(0 0 0 / var(--tw-ring-opacity)); -} - -.ring-opacity-5 { - --tw-ring-opacity: 0.05; -} - .hover\:bg-gray-100:hover { --tw-bg-opacity: 1; background-color: rgb(243 244 246 / var(--tw-bg-opacity)); } -.hover\:text-gray-500:hover { - --tw-text-opacity: 1; - color: rgb(107 114 128 / var(--tw-text-opacity)); -} - .focus\:outline-none:focus { outline: 2px solid transparent; outline-offset: 2px; @@ -1024,47 +975,27 @@ video { box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); } -.focus\:ring-indigo-500:focus { - --tw-ring-opacity: 1; - --tw-ring-color: rgb(99 102 241 / var(--tw-ring-opacity)); +.focus\:ring-4:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); } -.focus\:ring-offset-2:focus { - --tw-ring-offset-width: 2px; +.focus\:ring-gray-200:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(229 231 235 / var(--tw-ring-opacity)); +} + +.focus\:ring-gray-300:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(209 213 219 / var(--tw-ring-opacity)); } @media (min-width: 640px) { - .sm\:-my-px { - margin-top: -1px; - margin-bottom: -1px; - } - - .sm\:ml-6 { - margin-left: 1.5rem; - } - - .sm\:flex { - display: flex; - } - - .sm\:hidden { - display: none; - } - .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } - .sm\:items-center { - align-items: center; - } - - .sm\:space-x-8 > :not([hidden]) ~ :not([hidden]) { - --tw-space-x-reverse: 0; - margin-right: calc(2rem * var(--tw-space-x-reverse)); - margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse))); - } - .sm\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; @@ -1072,28 +1003,91 @@ video { } @media (min-width: 768px) { + .md\:order-1 { + order: 1; + } + + .md\:order-2 { + order: 2; + } + + .md\:me-0 { + margin-inline-end: 0px; + } + + .md\:mt-0 { + margin-top: 0px; + } + + .md\:flex { + display: flex; + } + + .md\:hidden { + display: none; + } + .md\:h-64 { height: 16rem; } - .md\:h-72 { - height: 18rem; + .md\:w-auto { + width: auto; + } + + .md\:flex-row { + flex-direction: row; + } + + .md\:space-x-0 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(0px * var(--tw-space-x-reverse)); + margin-left: calc(0px * calc(1 - var(--tw-space-x-reverse))); + } + + .md\:space-x-8 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(2rem * var(--tw-space-x-reverse)); + margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse))); + } + + .md\:border-0 { + border-width: 0px; + } + + .md\:bg-transparent { + background-color: transparent; + } + + .md\:bg-white { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); + } + + .md\:p-0 { + padding: 0px; } .md\:p-6 { padding: 1.5rem; } + + .md\:text-blue-700 { + --tw-text-opacity: 1; + color: rgb(29 78 216 / var(--tw-text-opacity)); + } + + .md\:hover\:bg-transparent:hover { + background-color: transparent; + } + + .md\:hover\:text-blue-700:hover { + --tw-text-opacity: 1; + color: rgb(29 78 216 / var(--tw-text-opacity)); + } } @media (min-width: 1024px) { - .lg\:block { - display: block; - } - - .lg\:hidden { - display: none; - } - .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } @@ -1104,7 +1098,16 @@ video { } } +.rtl\:space-x-reverse:where([dir="rtl"], [dir="rtl"] *) > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 1; +} + @media (prefers-color-scheme: dark) { + .dark\:divide-gray-600 > :not([hidden]) ~ :not([hidden]) { + --tw-divide-opacity: 1; + border-color: rgb(75 85 99 / var(--tw-divide-opacity)); + } + .dark\:border-gray-600 { --tw-border-opacity: 1; border-color: rgb(75 85 99 / var(--tw-border-opacity)); @@ -1120,6 +1123,26 @@ video { background-color: rgb(55 65 81 / var(--tw-bg-opacity)); } + .dark\:bg-gray-800 { + --tw-bg-opacity: 1; + background-color: rgb(31 41 55 / var(--tw-bg-opacity)); + } + + .dark\:bg-gray-900 { + --tw-bg-opacity: 1; + background-color: rgb(17 24 39 / var(--tw-bg-opacity)); + } + + .dark\:text-gray-200 { + --tw-text-opacity: 1; + color: rgb(229 231 235 / var(--tw-text-opacity)); + } + + .dark\:text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity)); + } + .dark\:text-gray-600 { --tw-text-opacity: 1; color: rgb(75 85 99 / var(--tw-text-opacity)); @@ -1129,4 +1152,52 @@ video { --tw-text-opacity: 1; color: rgb(55 65 81 / var(--tw-text-opacity)); } + + .dark\:text-white { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); + } + + .dark\:hover\:bg-gray-600:hover { + --tw-bg-opacity: 1; + background-color: rgb(75 85 99 / var(--tw-bg-opacity)); + } + + .dark\:hover\:bg-gray-700:hover { + --tw-bg-opacity: 1; + background-color: rgb(55 65 81 / var(--tw-bg-opacity)); + } + + .dark\:hover\:text-white:hover { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); + } + + .dark\:focus\:ring-gray-600:focus { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(75 85 99 / var(--tw-ring-opacity)); + } +} + +@media (min-width: 768px) { + @media (prefers-color-scheme: dark) { + .md\:dark\:bg-gray-900 { + --tw-bg-opacity: 1; + background-color: rgb(17 24 39 / var(--tw-bg-opacity)); + } + + .md\:dark\:text-blue-500 { + --tw-text-opacity: 1; + color: rgb(59 130 246 / var(--tw-text-opacity)); + } + + .md\:dark\:hover\:bg-transparent:hover { + background-color: transparent; + } + + .md\:dark\:hover\:text-blue-500:hover { + --tw-text-opacity: 1; + color: rgb(59 130 246 / var(--tw-text-opacity)); + } + } } diff --git a/crates/app/tailwind.config.js b/crates/app/tailwind.config.js index 601d56c..1c13bfe 100644 --- a/crates/app/tailwind.config.js +++ b/crates/app/tailwind.config.js @@ -1,7 +1,7 @@ /** @type {import('tailwindcss').Config} */ module.exports = { content: [ - './templates/**/*.html', + './src/**/*.html', './css/**/*.css', ], theme: { From 2236a7219b1e3fd97329705114899d28cc6bf629 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Fri, 23 Aug 2024 18:49:02 +0200 Subject: [PATCH 06/12] refacto: remove old_* directories --- crates/app/old_templates/hello.html | 1 - crates/app/old_templates/layout/nav.html | 41 ------------ .../layout/nav/desktop/menu-items.html | 9 --- .../nav/desktop/notifications-button.html | 6 -- .../layout/nav/desktop/profile-dropdown.html | 22 ------- .../layout/nav/desktop/profile.html | 27 -------- crates/app/old_templates/layout/nav/logo.html | 4 -- .../layout/nav/mobile/menu-button.html | 43 ------------- .../layout/nav/mobile/menu-items.html | 9 --- .../nav/mobile/notifications-button.html | 6 -- .../layout/nav/mobile/profile-items.html | 9 --- .../layout/nav/mobile/profile.html | 11 ---- .../layout/nav/nav-menu-items.html | 14 ----- .../layout/nav/notifications-icon.html | 16 ----- .../layout/nav/profile-menu-items.html | 11 ---- crates/app/old_templates/pages/cps.html | 52 --------------- crates/app/old_templates/pages/home.html | 52 --------------- crates/app/src/old_pages/home.rs | 9 --- crates/app/src/old_templates/hello.rs | 18 ------ crates/app/src/old_templates/mod.rs | 12 ---- crates/app/src/old_templates/nav.rs | 60 ------------------ crates/app/src/old_templates/profile.rs | 63 ------------------- 22 files changed, 495 deletions(-) delete mode 100644 crates/app/old_templates/hello.html delete mode 100644 crates/app/old_templates/layout/nav.html delete mode 100644 crates/app/old_templates/layout/nav/desktop/menu-items.html delete mode 100644 crates/app/old_templates/layout/nav/desktop/notifications-button.html delete mode 100644 crates/app/old_templates/layout/nav/desktop/profile-dropdown.html delete mode 100644 crates/app/old_templates/layout/nav/desktop/profile.html delete mode 100644 crates/app/old_templates/layout/nav/logo.html delete mode 100644 crates/app/old_templates/layout/nav/mobile/menu-button.html delete mode 100644 crates/app/old_templates/layout/nav/mobile/menu-items.html delete mode 100644 crates/app/old_templates/layout/nav/mobile/notifications-button.html delete mode 100644 crates/app/old_templates/layout/nav/mobile/profile-items.html delete mode 100644 crates/app/old_templates/layout/nav/mobile/profile.html delete mode 100644 crates/app/old_templates/layout/nav/nav-menu-items.html delete mode 100644 crates/app/old_templates/layout/nav/notifications-icon.html delete mode 100644 crates/app/old_templates/layout/nav/profile-menu-items.html delete mode 100644 crates/app/old_templates/pages/cps.html delete mode 100644 crates/app/old_templates/pages/home.html delete mode 100644 crates/app/src/old_pages/home.rs delete mode 100644 crates/app/src/old_templates/hello.rs delete mode 100644 crates/app/src/old_templates/mod.rs delete mode 100644 crates/app/src/old_templates/nav.rs delete mode 100644 crates/app/src/old_templates/profile.rs diff --git a/crates/app/old_templates/hello.html b/crates/app/old_templates/hello.html deleted file mode 100644 index c45d96e..0000000 --- a/crates/app/old_templates/hello.html +++ /dev/null @@ -1 +0,0 @@ -
    Hello {{name}}!
    diff --git a/crates/app/old_templates/layout/nav.html b/crates/app/old_templates/layout/nav.html deleted file mode 100644 index 872267f..0000000 --- a/crates/app/old_templates/layout/nav.html +++ /dev/null @@ -1,41 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/desktop/menu-items.html b/crates/app/old_templates/layout/nav/desktop/menu-items.html deleted file mode 100644 index 51a8e6b..0000000 --- a/crates/app/old_templates/layout/nav/desktop/menu-items.html +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/desktop/notifications-button.html b/crates/app/old_templates/layout/nav/desktop/notifications-button.html deleted file mode 100644 index f11c45e..0000000 --- a/crates/app/old_templates/layout/nav/desktop/notifications-button.html +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/desktop/profile-dropdown.html b/crates/app/old_templates/layout/nav/desktop/profile-dropdown.html deleted file mode 100644 index 73667f7..0000000 --- a/crates/app/old_templates/layout/nav/desktop/profile-dropdown.html +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/desktop/profile.html b/crates/app/old_templates/layout/nav/desktop/profile.html deleted file mode 100644 index b0ceabc..0000000 --- a/crates/app/old_templates/layout/nav/desktop/profile.html +++ /dev/null @@ -1,27 +0,0 @@ - -
    -
    - -
    - - {% include "layout/nav/desktop/profile-dropdown.html" %} -
    diff --git a/crates/app/old_templates/layout/nav/logo.html b/crates/app/old_templates/layout/nav/logo.html deleted file mode 100644 index b7a5c3d..0000000 --- a/crates/app/old_templates/layout/nav/logo.html +++ /dev/null @@ -1,4 +0,0 @@ -
    - Your Company - -
    \ No newline at end of file diff --git a/crates/app/old_templates/layout/nav/mobile/menu-button.html b/crates/app/old_templates/layout/nav/mobile/menu-button.html deleted file mode 100644 index c59e6e4..0000000 --- a/crates/app/old_templates/layout/nav/mobile/menu-button.html +++ /dev/null @@ -1,43 +0,0 @@ - - diff --git a/crates/app/old_templates/layout/nav/mobile/menu-items.html b/crates/app/old_templates/layout/nav/mobile/menu-items.html deleted file mode 100644 index 1bece64..0000000 --- a/crates/app/old_templates/layout/nav/mobile/menu-items.html +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/mobile/notifications-button.html b/crates/app/old_templates/layout/nav/mobile/notifications-button.html deleted file mode 100644 index 5525de9..0000000 --- a/crates/app/old_templates/layout/nav/mobile/notifications-button.html +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/crates/app/old_templates/layout/nav/mobile/profile-items.html b/crates/app/old_templates/layout/nav/mobile/profile-items.html deleted file mode 100644 index 9f84346..0000000 --- a/crates/app/old_templates/layout/nav/mobile/profile-items.html +++ /dev/null @@ -1,9 +0,0 @@ -
    - Chargement ... -
    diff --git a/crates/app/old_templates/layout/nav/mobile/profile.html b/crates/app/old_templates/layout/nav/mobile/profile.html deleted file mode 100644 index 03851b7..0000000 --- a/crates/app/old_templates/layout/nav/mobile/profile.html +++ /dev/null @@ -1,11 +0,0 @@ -
    - -
    -
    -
    Tom Cook
    -
    tom@example.com
    -
    diff --git a/crates/app/old_templates/layout/nav/nav-menu-items.html b/crates/app/old_templates/layout/nav/nav-menu-items.html deleted file mode 100644 index f9de594..0000000 --- a/crates/app/old_templates/layout/nav/nav-menu-items.html +++ /dev/null @@ -1,14 +0,0 @@ -{% for item in items %} - - {{ item.label }} - -{% endfor %} \ No newline at end of file diff --git a/crates/app/old_templates/layout/nav/notifications-icon.html b/crates/app/old_templates/layout/nav/notifications-icon.html deleted file mode 100644 index 7f645d7..0000000 --- a/crates/app/old_templates/layout/nav/notifications-icon.html +++ /dev/null @@ -1,16 +0,0 @@ - -View notifications - \ No newline at end of file diff --git a/crates/app/old_templates/layout/nav/profile-menu-items.html b/crates/app/old_templates/layout/nav/profile-menu-items.html deleted file mode 100644 index 95b0064..0000000 --- a/crates/app/old_templates/layout/nav/profile-menu-items.html +++ /dev/null @@ -1,11 +0,0 @@ -{% for item in items %} - - {{ item.label }} - -{% endfor %} diff --git a/crates/app/old_templates/pages/cps.html b/crates/app/old_templates/pages/cps.html deleted file mode 100644 index 3df33d7..0000000 --- a/crates/app/old_templates/pages/cps.html +++ /dev/null @@ -1,52 +0,0 @@ -

    - CPS -

    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    diff --git a/crates/app/old_templates/pages/home.html b/crates/app/old_templates/pages/home.html deleted file mode 100644 index c7cf418..0000000 --- a/crates/app/old_templates/pages/home.html +++ /dev/null @@ -1,52 +0,0 @@ -

    - Accueil -

    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    diff --git a/crates/app/src/old_pages/home.rs b/crates/app/src/old_pages/home.rs deleted file mode 100644 index 791c63f..0000000 --- a/crates/app/src/old_pages/home.rs +++ /dev/null @@ -1,9 +0,0 @@ -use askama_axum::Template; - -#[derive(Template)] -#[template(path = "pages/home.html")] -pub struct HomeTemplate; - -pub async fn home() -> HomeTemplate { - HomeTemplate -} diff --git a/crates/app/src/old_templates/hello.rs b/crates/app/src/old_templates/hello.rs deleted file mode 100644 index 58ae568..0000000 --- a/crates/app/src/old_templates/hello.rs +++ /dev/null @@ -1,18 +0,0 @@ -use askama_axum::Template; -use axum::{routing, Router}; - -#[derive(Template)] -#[template(path = "hello.html")] -struct HelloTemplate { - pub name: String, -} - -async fn hello() -> HelloTemplate { - HelloTemplate { - name: "Theo".to_string(), - } -} - -pub fn get_routes() -> Router { - Router::new().route("/", routing::get(hello)) -} diff --git a/crates/app/src/old_templates/mod.rs b/crates/app/src/old_templates/mod.rs deleted file mode 100644 index c0b91c0..0000000 --- a/crates/app/src/old_templates/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -use axum::Router; - -mod hello; -mod nav; -mod profile; - -pub fn get_routes() -> Router { - Router::new() - .nest("/hello", hello::get_routes()) - .nest("/nav", nav::get_routes()) - .nest("/profile", profile::get_routes()) -} diff --git a/crates/app/src/old_templates/nav.rs b/crates/app/src/old_templates/nav.rs deleted file mode 100644 index 9bb44cc..0000000 --- a/crates/app/src/old_templates/nav.rs +++ /dev/null @@ -1,60 +0,0 @@ -use askama_axum::Template; -use axum::{extract::Query, routing, Router}; -use serde::Deserialize; - -struct MenuItem { - label: String, - href: String, - current: bool, -} - -#[derive(Deserialize)] -struct MenuParameters { - mobile: bool, -} - -#[derive(Template)] -#[template(path = "layout/nav/nav-menu-items.html")] -struct MenuTemplate { - mobile: bool, - items: Vec, -} - -impl MenuTemplate { - fn get_classes(&self, is_current_item: &bool) -> String { - let common_classes = match self.mobile { - true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(), - false => { - "inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium".to_string() - } - }; - match (self.mobile, is_current_item) { - (true, true) => common_classes + " border-indigo-500 bg-indigo-50 text-indigo-700", - (true, false) => common_classes + " border-transparent text-gray-600 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-800", - (false, true) => common_classes + " border-indigo-500 text-gray-900", - (false, false) => common_classes + " border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700", - } - } -} - -async fn menu(Query(params): Query) -> MenuTemplate { - MenuTemplate { - mobile: params.mobile, - items: vec![ - MenuItem { - label: "Accueil".to_string(), - href: "/pages/home".to_string(), - current: true, - }, - MenuItem { - label: "CPS".to_string(), - href: "/pages/cps".to_string(), - current: false, - }, - ], - } -} - -pub fn get_routes() -> Router { - Router::new().route("/menu", routing::get(menu)) -} diff --git a/crates/app/src/old_templates/profile.rs b/crates/app/src/old_templates/profile.rs deleted file mode 100644 index 60a915a..0000000 --- a/crates/app/src/old_templates/profile.rs +++ /dev/null @@ -1,63 +0,0 @@ -use askama_axum::Template; -use axum::{extract::Query, routing, Router}; -use serde::Deserialize; - -struct MenuItem { - label: String, - id: String, - current: bool, -} - -#[derive(Deserialize)] -struct MenuParameters { - mobile: bool, -} - -#[derive(Template)] -#[template(path = "layout/nav/profile-menu-items.html")] -struct MenuTemplate { - mobile: bool, - items: Vec, -} - -impl MenuTemplate { - fn get_classes(&self, is_current_item: &bool) -> String { - let common_classes = match self.mobile { - true => "block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800".to_string(), - false => "block px-4 py-2 text-sm text-gray-700".to_string(), - }; - match (self.mobile, is_current_item) { - (true, true) => common_classes + "", // ??? - (true, false) => common_classes + "", - (false, true) => common_classes + " bg-gray-100", - (false, false) => common_classes + "", - } - } -} - -async fn menu(Query(params): Query) -> MenuTemplate { - MenuTemplate { - mobile: params.mobile, - items: vec![ - MenuItem { - label: "Votre profil".to_string(), - id: "profile".to_string(), - current: false, - }, - MenuItem { - label: "Paramètres".to_string(), - id: "settings".to_string(), - current: false, - }, - MenuItem { - label: "Déconnexion".to_string(), - id: "logout".to_string(), - current: false, - }, - ], - } -} - -pub fn get_routes() -> Router { - Router::new().route("/menu", routing::get(menu)) -} From 7d4dc81df2fc6cf3ea3f2ef4b190c33064c03128 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Fri, 23 Aug 2024 19:46:28 +0200 Subject: [PATCH 07/12] feat: implement htmx with partials on index and cps pages --- Cargo.lock | 30 +++++++++++++++++ crates/app/Cargo.toml | 1 + crates/app/src/components/base.html | 5 +++ .../app/src/components/navbar/menu-item.html | 4 +++ crates/app/src/components/navbar/navbar.html | 2 +- crates/app/src/lib.rs | 10 ++++-- crates/app/src/pages/cps.html | 17 +++++----- crates/app/src/pages/cps.rs | 32 +++---------------- crates/app/src/pages/index.html | 5 ++- 9 files changed, 63 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be45b77..2df2156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,7 @@ dependencies = [ "askama", "askama_axum", "axum", + "axum-htmx", "cargo-watch", "listenfd", "notify 6.1.1", @@ -398,6 +399,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-htmx" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36cdb6062317f732ed3acf4e9c28c3824092e226726616f46ebdd8cd32c82a41" +dependencies = [ + "async-trait", + "axum-core", + "futures", + "http", + "tokio", + "tower", +] + [[package]] name = "backtrace" version = "0.3.73" @@ -1470,6 +1485,20 @@ dependencies = [ "new_debug_unreachable", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -1477,6 +1506,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml index e095c3a..175b803 100644 --- a/crates/app/Cargo.toml +++ b/crates/app/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" askama = "0.12.1" askama_axum = "0.4.0" axum = "0.7.5" +axum-htmx = { version = "0.6", features = ["auto-vary"] } listenfd = "1.0.1" notify = "6.1.1" serde = { version = "1.0.204", features = ["derive"] } diff --git a/crates/app/src/components/base.html b/crates/app/src/components/base.html index 651fb67..c128735 100644 --- a/crates/app/src/components/base.html +++ b/crates/app/src/components/base.html @@ -1,3 +1,7 @@ +{% if hx_request %} + {% block title %}{{ title }}{% endblock %} + {% block body %}{% endblock %} +{% else %} @@ -17,3 +21,4 @@ +{% endif %} diff --git a/crates/app/src/components/navbar/menu-item.html b/crates/app/src/components/navbar/menu-item.html index b002e0c..fe0a264 100644 --- a/crates/app/src/components/navbar/menu-item.html +++ b/crates/app/src/components/navbar/menu-item.html @@ -8,6 +8,10 @@ {% else -%} class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700" {% endif -%} + hx-get="{{ item.href }}" + hx-push-url="true" + hx-swap="outerHTML" + hx-select-oob="#menu-items,#page-header,#page-main" > {{ item.label }} diff --git a/crates/app/src/components/navbar/navbar.html b/crates/app/src/components/navbar/navbar.html index 24a8af6..be4bd0f 100644 --- a/crates/app/src/components/navbar/navbar.html +++ b/crates/app/src/components/navbar/navbar.html @@ -39,7 +39,7 @@