diff --git a/src/application/routes/app/add.rs b/src/application/routes/app/add.rs index 32eb658..3f3f623 100644 --- a/src/application/routes/app/add.rs +++ b/src/application/routes/app/add.rs @@ -48,6 +48,7 @@ const ADD_TABS: &[Tab] = &[ pub(crate) struct AddQuery { #[serde(rename = "type", default = "default_type")] entity_type: String, + bag_id: Option, } fn default_type() -> String { @@ -100,6 +101,7 @@ pub(crate) async fn add_page( cafe_options, defaults: brew_form.defaults, quick_note_options: brew_form.quick_note_options, + pre_select_bag_id: query.bag_id, }; render_html(template).map(IntoResponse::into_response) diff --git a/src/presentation/web/templates.rs b/src/presentation/web/templates.rs index 6549ba1..73be525 100644 --- a/src/presentation/web/templates.rs +++ b/src/presentation/web/templates.rs @@ -172,6 +172,7 @@ pub struct AddTemplate { pub cafe_options: Vec, pub defaults: BrewDefaultsView, pub quick_note_options: Vec, + pub pre_select_bag_id: Option, } pub fn render_template(template: T) -> Result { diff --git a/static/js/components/searchable-select.js b/static/js/components/searchable-select.js index bbbedf6..d8ed7f7 100644 --- a/static/js/components/searchable-select.js +++ b/static/js/components/searchable-select.js @@ -47,6 +47,17 @@ customElements.define("searchable-select", class extends HTMLElement { this.appendChild(searchWrap); this.appendChild(selectedWrap); + const initialValue = this.getAttribute("initial-value"); + if (initialValue) { + const match = buttons.find((btn) => btn.value === initialValue); + if (match) { + hidden.value = match.value; + display.textContent = match.dataset.display; + searchWrap.classList.add("hidden"); + selectedWrap.classList.remove("hidden"); + } + } + search.addEventListener("input", () => { const q = search.value.toLowerCase(); options.classList.toggle("hidden", !q); diff --git a/templates/pages/add.html b/templates/pages/add.html index 12a7534..88bcfac 100644 --- a/templates/pages/add.html +++ b/templates/pages/add.html @@ -257,7 +257,7 @@
Bag * - + {% for bag in bag_options %}