Implémentation "HATEOAS" de l'interface pour HTMX et update des URLs qui fonctionne ! #57

Merged
florian_briand merged 12 commits from feat/54_update_url_on_navbar_navigation into main 2024-08-30 18:25:53 +02:00
Showing only changes of commit 6dbf5b5438 - Show all commits

View File

@ -1,9 +1,34 @@
use askama_axum::Template; use askama_axum::Template;
use axum::{
async_trait,
extract::FromRequestParts,
http::{request::Parts, HeaderMap, StatusCode},
};
#[derive(Template)] #[derive(Template)]
#[template(path = "pages/cps.html")] #[template(path = "pages/cps.html")]
pub struct CpsTemplate; pub struct CpsTemplate;
pub async fn cps() -> CpsTemplate { pub struct ExtractHxRequest(bool);
#[async_trait]
impl<S> FromRequestParts<S> for ExtractHxRequest
where
S: Send + Sync,
{
type Rejection = (StatusCode, &'static str);
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
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 CpsTemplate
} }