From 705f8d99024811f149936dc3bbee9bdb7d7987e1 Mon Sep 17 00:00:00 2001 From: Wes Holland Date: Sat, 15 Feb 2025 08:42:33 -0600 Subject: [PATCH] Improve item-create toasts --- src/app/catalog.rs | 4 ++-- src/app/item/create.rs | 13 ++++++++++++- .../catalog-item-table.html} | 0 templates/{ => catalog}/catalog.html | 6 ++++-- templates/item/item-create-form.html | 3 ++- 5 files changed, 20 insertions(+), 6 deletions(-) rename templates/{catalog_item_fragment.html => catalog/catalog-item-table.html} (100%) rename templates/{ => catalog}/catalog.html (95%) diff --git a/src/app/catalog.rs b/src/app/catalog.rs index 0901d1a..f2365c3 100644 --- a/src/app/catalog.rs +++ b/src/app/catalog.rs @@ -8,14 +8,14 @@ use crate::error::{AppError, QueryExtractor}; use crate::app::common::query_args::search::SearchQueryArgs; #[derive(Template)] -#[template(path = "catalog.html")] +#[template(path = "catalog/catalog.html")] struct CatalogTemplate { items: Vec, query: SearchQueryArgs, } #[derive(Template)] -#[template(path = "catalog_item_fragment.html")] +#[template(path = "catalog/catalog-item-table.html")] struct CatalogItemFragmentTemplate { items: Vec } diff --git a/src/app/item/create.rs b/src/app/item/create.rs index 6baeed7..04cb199 100644 --- a/src/app/item/create.rs +++ b/src/app/item/create.rs @@ -4,6 +4,7 @@ use askama::Template; use askama_axum::{IntoResponse, Response}; use axum::extract::State; use axum::{async_trait, debug_handler, Form}; +use axum_htmx::{HxEvent, HxResponseTrigger}; use serde::Deserialize; use tracing::info; use crate::app::routes::AppState; @@ -168,7 +169,17 @@ pub async fn create_item_form_post( &form_data.pims_id, &form_data.vetcove_id, ).await?; - Ok(CreateItemFormData::base_template(&state).await?.into_response()) + let fresh_form = CreateItemFormData::base_template(&state).await?; + + let events = vec![ + HxEvent::from("form-submit-success"), + HxEvent::from("new-item"), + ]; + + Ok( ( + HxResponseTrigger::normal(events), + fresh_form.into_response() + ).into_response() ) } #[debug_handler] diff --git a/templates/catalog_item_fragment.html b/templates/catalog/catalog-item-table.html similarity index 100% rename from templates/catalog_item_fragment.html rename to templates/catalog/catalog-item-table.html diff --git a/templates/catalog.html b/templates/catalog/catalog.html similarity index 95% rename from templates/catalog.html rename to templates/catalog/catalog.html index 1908394..a301c75 100644 --- a/templates/catalog.html +++ b/templates/catalog/catalog.html @@ -3,7 +3,9 @@ {% block content %} -
+
@@ -83,7 +85,7 @@
- {% include "catalog_item_fragment.html" %} + {% include "catalog-item-table.html" %}
diff --git a/templates/item/item-create-form.html b/templates/item/item-create-form.html index 0d5da99..c303436 100644 --- a/templates/item/item-create-form.html +++ b/templates/item/item-create-form.html @@ -3,7 +3,8 @@ hx-post="/item/create" hx-target="this" hx-swap="outerHTML" - x-on:htmx:response-error="$dispatch('notice', {type: 'error', text: 'Unknown error!'})" + x-on:htmx:response-error="$dispatch('notice', {type: 'error', text: 'Unknown error'})" + x-on:form-submit-success="$dispatch('notice', {type: 'info', text: 'New item created'})" >