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:
@@ -1,16 +1,22 @@
|
||||
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::entry::Entry;
|
||||
use crate::partials::{layout::Layout, entry_list::entry_list};
|
||||
use crate::partials::{entry_list::entry_list, layout::Layout};
|
||||
|
||||
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 = Default::default();
|
||||
let entries = Entry::get_all(&pool, &options).await?;
|
||||
Ok(layout.render(html! {
|
||||
Ok(layout.boosted(hx_boosted).render(html! {
|
||||
ul class="entries" {
|
||||
(entry_list(entries, &options))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user