feat: implement htmx with partials on index and cps pages

This commit is contained in:
2024-08-23 19:46:28 +02:00
committed by florian_briand
parent 2236a7219b
commit 7d4dc81df2
9 changed files with 63 additions and 43 deletions

View File

@ -1,34 +1,12 @@
use askama_axum::Template;
use axum::{
async_trait,
extract::FromRequestParts,
http::{request::Parts, HeaderMap, StatusCode},
};
use axum_htmx::HxRequest;
#[derive(Template)]
#[template(path = "cps.html")]
pub struct 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 struct CpsTemplate {
hx_request: bool,
}
pub async fn cps(headers: HeaderMap, hx_request: ExtractHxRequest) -> CpsTemplate {
println!("{:#?}", headers);
println!("{:#?}", hx_request.0);
CpsTemplate
pub async fn cps(HxRequest(hx_request): HxRequest) -> CpsTemplate {
CpsTemplate { hx_request }
}