add data-driven navigation with admin editor
All checks were successful
deploy / deploy (push) Successful in 1m34s
All checks were successful
deploy / deploy (push) Successful in 1m34s
Replace hardcoded header, footer and mobile nav with settings-driven loops. Nav items stored as JSON via Settings, loaded in ThemeHook with sensible defaults. New admin navigation editor at /admin/navigation for add/remove/reorder/save/reset. Mobile bottom nav also driven from header nav items with icon mapping by slug. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,28 @@ defmodule BerrypodWeb.ThemeHook do
|
||||
alias Berrypod.{Products, Settings, Media}
|
||||
alias Berrypod.Theme.{CSSCache, CSSGenerator}
|
||||
|
||||
@default_header_nav [
|
||||
%{"label" => "Home", "href" => "/", "slug" => "home"},
|
||||
%{
|
||||
"label" => "Shop",
|
||||
"href" => "/collections/all",
|
||||
"slug" => "collection",
|
||||
"active_slugs" => ["collection", "pdp"]
|
||||
},
|
||||
%{"label" => "About", "href" => "/about", "slug" => "about"},
|
||||
%{"label" => "Contact", "href" => "/contact", "slug" => "contact"}
|
||||
]
|
||||
|
||||
@default_footer_nav [
|
||||
%{"label" => "Delivery & returns", "href" => "/delivery", "slug" => "delivery"},
|
||||
%{"label" => "Privacy policy", "href" => "/privacy", "slug" => "privacy"},
|
||||
%{"label" => "Terms of service", "href" => "/terms", "slug" => "terms"},
|
||||
%{"label" => "Contact", "href" => "/contact", "slug" => "contact"}
|
||||
]
|
||||
|
||||
def default_header_nav, do: @default_header_nav
|
||||
def default_footer_nav, do: @default_footer_nav
|
||||
|
||||
def on_mount(:mount_theme, _params, _session, socket) do
|
||||
theme_settings = Settings.get_theme_settings()
|
||||
|
||||
@@ -43,6 +65,8 @@ defmodule BerrypodWeb.ThemeHook do
|
||||
:is_admin,
|
||||
!!(socket.assigns[:current_scope] && socket.assigns.current_scope.user)
|
||||
)
|
||||
|> assign(:header_nav_items, load_nav("header_nav", @default_header_nav))
|
||||
|> assign(:footer_nav_items, load_nav("footer_nav", @default_footer_nav))
|
||||
|
||||
{:cont, socket}
|
||||
end
|
||||
@@ -64,4 +88,11 @@ defmodule BerrypodWeb.ThemeHook do
|
||||
{:halt, Phoenix.LiveView.redirect(socket, to: "/coming-soon")}
|
||||
end
|
||||
end
|
||||
|
||||
defp load_nav(key, default) do
|
||||
case Settings.get_setting(key) do
|
||||
items when is_list(items) -> items
|
||||
_ -> default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user