Add hx-boosted support to Layout

It will now skip rendering the layout if the request is coming from an
hx-boosted link or form and only update the head title with a
hx-swap-oob.
This commit is contained in:
2023-09-26 23:36:31 -04:00
parent 81b4ef860e
commit 092a38ad52
12 changed files with 191 additions and 78 deletions

View File

@@ -1,29 +1,38 @@
use axum::extract::State;
use axum::response::Response;
use axum::TypedHeader;
use maud::html;
use sqlx::PgPool;
use crate::error::Result;
use crate::htmx::HXBoosted;
use crate::models::feed::{Feed, GetFeedsOptions};
use crate::partials::add_feed_form::add_feed_form;
use crate::partials::feed_list::feed_list;
use crate::partials::layout::Layout;
use crate::partials::opml_import_form::opml_import_form;
pub async fn get(State(pool): State<PgPool>, layout: Layout) -> Result<Response> {
pub async fn get(
State(pool): State<PgPool>,
hx_boosted: Option<TypedHeader<HXBoosted>>,
layout: Layout,
) -> Result<Response> {
let options = GetFeedsOptions::default();
let feeds = Feed::get_all(&pool, &options).await?;
Ok(layout.with_subtitle("feeds").render(html! {
header { h2 { "Feeds" } }
div class="feeds" {
ul id="feeds" {
(feed_list(feeds, &options))
Ok(layout
.with_subtitle("feeds")
.boosted(hx_boosted)
.render(html! {
header { h2 { "Feeds" } }
div class="feeds" {
ul id="feeds" {
(feed_list(feeds, &options))
}
div class="add-feed" {
h3 { "Add Feed" }
(add_feed_form())
(opml_import_form())
}
}
div class="add-feed" {
h3 { "Add Feed" }
(add_feed_form())
(opml_import_form())
}
}
}))
}))
}