Use HX-Target, not HX-Boost for Layout render

HX-Boost is not always sent in all AJAX requests that htmx sends, only
those initiated by an element with hx-boost enabled. It was not showing
up on requests following an HX-Redirect response.

After reading the docs more, I realized HX-Target was what I wanted. If
I can see that the request is targeting `#main-content` then I know to
only return HTML inside that element. Simple.
This commit is contained in:
2023-09-27 01:28:53 -04:00
parent bea3529e22
commit a72bfa15bd
10 changed files with 110 additions and 60 deletions

View File

@@ -5,7 +5,7 @@ use maud::html;
use sqlx::PgPool;
use crate::error::Result;
use crate::htmx::HXBoosted;
use crate::htmx::HXTarget;
use crate::models::feed::{Feed, GetFeedsOptions};
use crate::partials::add_feed_form::add_feed_form;
use crate::partials::feed_list::feed_list;
@@ -14,14 +14,14 @@ use crate::partials::opml_import_form::opml_import_form;
pub async fn get(
State(pool): State<PgPool>,
hx_boosted: Option<TypedHeader<HXBoosted>>,
hx_target: Option<TypedHeader<HXTarget>>,
layout: Layout,
) -> Result<Response> {
let options = GetFeedsOptions::default();
let feeds = Feed::get_all(&pool, &options).await?;
Ok(layout
.with_subtitle("feeds")
.boosted(hx_boosted)
.targeted(hx_target)
.render(html! {
header { h2 { "Feeds" } }
div class="feeds" {