diff --git a/assets/js/app.js b/assets/js/app.js index 8744a43..1b0a167 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -380,6 +380,7 @@ const SearchModal = { open() { this.el.style.display = "flex" + this.pushEvent("open_search", {}) const input = this.el.querySelector("#search-input") if (input) { input.focus() diff --git a/lib/simpleshop_theme_web/components/layouts/shop.html.heex b/lib/simpleshop_theme_web/components/layouts/shop.html.heex index f96c5b7..86b3e32 100644 --- a/lib/simpleshop_theme_web/components/layouts/shop.html.heex +++ b/lib/simpleshop_theme_web/components/layouts/shop.html.heex @@ -1,13 +1,2 @@ -
- <.link - href={~p"/admin"} - style="color: var(--t-text-secondary, #666); text-decoration: none;" - > - Admin - -
<.shop_flash_group flash={@flash} /> {@inner_content} diff --git a/lib/simpleshop_theme_web/components/page_templates/cart.html.heex b/lib/simpleshop_theme_web/components/page_templates/cart.html.heex index 214e581..276b91e 100644 --- a/lib/simpleshop_theme_web/components/page_templates/cart.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/cart.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="cart" - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="cart">
<.page_title text="Your basket" /> diff --git a/lib/simpleshop_theme_web/components/page_templates/checkout_success.html.heex b/lib/simpleshop_theme_web/components/page_templates/checkout_success.html.heex index e282657..795012f 100644 --- a/lib/simpleshop_theme_web/components/page_templates/checkout_success.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/checkout_success.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="checkout" - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="checkout">
<%= if @order && @order.payment_status == "paid" do %>
diff --git a/lib/simpleshop_theme_web/components/page_templates/collection.html.heex b/lib/simpleshop_theme_web/components/page_templates/collection.html.heex index 93bec5a..b2ccddf 100644 --- a/lib/simpleshop_theme_web/components/page_templates/collection.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/collection.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="collection" - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="collection">
<.collection_header title="All Products" product_count={length(assigns[:products] || [])} /> diff --git a/lib/simpleshop_theme_web/components/page_templates/contact.html.heex b/lib/simpleshop_theme_web/components/page_templates/contact.html.heex index 05b2366..dfa579d 100644 --- a/lib/simpleshop_theme_web/components/page_templates/contact.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/contact.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="contact" - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="contact">
<.hero_section variant={:page} diff --git a/lib/simpleshop_theme_web/components/page_templates/content.html.heex b/lib/simpleshop_theme_web/components/page_templates/content.html.heex index ff02300..dfa0cf2 100644 --- a/lib/simpleshop_theme_web/components/page_templates/content.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/content.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page={@active_page} - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)}>
<%= if assigns[:hero_background] do %> <.hero_section diff --git a/lib/simpleshop_theme_web/components/page_templates/error.html.heex b/lib/simpleshop_theme_web/components/page_templates/error.html.heex index f4c4612..33931c2 100644 --- a/lib/simpleshop_theme_web/components/page_templates/error.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/error.html.heex @@ -1,18 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="error" - error_page - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="error" error_page>
+<.shop_layout {layout_assigns(assigns)} active_page="home">
<.hero_section title="Original designs, printed on demand" diff --git a/lib/simpleshop_theme_web/components/page_templates/pdp.html.heex b/lib/simpleshop_theme_web/components/page_templates/pdp.html.heex index 12a43e6..c431dd2 100644 --- a/lib/simpleshop_theme_web/components/page_templates/pdp.html.heex +++ b/lib/simpleshop_theme_web/components/page_templates/pdp.html.heex @@ -1,17 +1,4 @@ -<.shop_layout - theme_settings={@theme_settings} - logo_image={@logo_image} - header_image={@header_image} - mode={@mode} - cart_items={@cart_items} - cart_count={@cart_count} - cart_subtotal={@cart_subtotal} - cart_drawer_open={assigns[:cart_drawer_open] || false} - cart_status={assigns[:cart_status]} - active_page="pdp" - search_query={assigns[:search_query] || ""} - search_results={assigns[:search_results] || []} -> +<.shop_layout {layout_assigns(assigns)} active_page="pdp">
<.breadcrumb items={ diff --git a/lib/simpleshop_theme_web/components/shop_components/layout.ex b/lib/simpleshop_theme_web/components/shop_components/layout.ex index 2c300b6..ac3f7a4 100644 --- a/lib/simpleshop_theme_web/components/shop_components/layout.ex +++ b/lib/simpleshop_theme_web/components/shop_components/layout.ex @@ -49,6 +49,25 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do """ end + # Keys accepted by shop_layout — used by layout_assigns/1 so page templates + # can spread assigns without listing each one explicitly. + @layout_keys ~w(theme_settings logo_image header_image mode cart_items cart_count + cart_subtotal cart_drawer_open cart_status active_page error_page is_admin + search_query search_results search_open categories)a + + @doc """ + Extracts the assigns relevant to `shop_layout` from a full assigns map. + + Page templates can use this instead of listing every attr explicitly: + + <.shop_layout {layout_assigns(assigns)} active_page="home"> + ... + + """ + def layout_assigns(assigns) do + Map.take(assigns, @layout_keys) + end + @doc """ Wraps page content in the standard shop shell: container, header, footer, cart drawer, search modal, and mobile bottom nav. @@ -67,8 +86,10 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do attr :cart_status, :string, default: nil attr :active_page, :string, required: true attr :error_page, :boolean, default: false + attr :is_admin, :boolean, default: false attr :search_query, :string, default: "" attr :search_results, :list, default: [] + attr :search_open, :boolean, default: false slot :inner_block, required: true @@ -93,6 +114,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do active_page={@active_page} mode={@mode} cart_count={@cart_count} + is_admin={@is_admin} /> {render_slot(@inner_block)} @@ -116,6 +138,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do hint_text={~s(Try a search – e.g. "mountain" or "notebook")} search_query={@search_query} search_results={@search_results} + search_open={@search_open} /> <.mobile_bottom_nav :if={!@error_page} active_page={@active_page} mode={@mode} /> @@ -336,6 +359,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do attr :hint_text, :string, default: nil attr :search_query, :string, default: "" attr :search_results, :list, default: [] + attr :search_open, :boolean, default: false def search_modal(assigns) do alias SimpleshopTheme.Cart @@ -357,7 +381,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do