feat: make htmx check more specific
parent
4c84c944d4
commit
f980115d45
|
@ -13,9 +13,16 @@ use tower_http::set_header::SetResponseHeaderLayer;
|
|||
use crate::db;
|
||||
|
||||
const HX_REQUEST_HEADER: &str = "HX-Request";
|
||||
const HX_HISTORY_RESTORE_HEADER: &str = "HX-History-Restore-Request";
|
||||
|
||||
pub fn is_htmx_req(headers: &HeaderMap) -> bool {
|
||||
headers.get(HX_REQUEST_HEADER).is_some()
|
||||
pub fn render_partial(headers: &HeaderMap) -> bool {
|
||||
let is_htmx_req = headers.get(HX_REQUEST_HEADER).is_some();
|
||||
let is_hist_restore_req = headers
|
||||
.get(HX_HISTORY_RESTORE_HEADER)
|
||||
.map(|val| val == HeaderValue::from_static("true"))
|
||||
.unwrap_or(false);
|
||||
|
||||
is_htmx_req && !is_hist_restore_req
|
||||
}
|
||||
|
||||
pub fn app(ctx: crate::Context) -> axum::Router {
|
||||
|
|
|
@ -9,7 +9,7 @@ use tera::Context;
|
|||
|
||||
use crate::db;
|
||||
|
||||
use super::is_htmx_req;
|
||||
use super::render_partial;
|
||||
|
||||
pub fn app(ctx: crate::Context) -> axum::Router {
|
||||
Router::new()
|
||||
|
@ -31,7 +31,7 @@ async fn get_plant_page(
|
|||
let mut context = Context::new();
|
||||
context.insert("plant", &plant);
|
||||
|
||||
let tmpl = if is_htmx_req(&headers) {
|
||||
let tmpl = if render_partial(&headers) {
|
||||
"partials/plant_info.html"
|
||||
} else {
|
||||
"plant_page.html"
|
||||
|
|
Loading…
Reference in New Issue