add Site context with social links editor and site-wide settings
Some checks failed
deploy / deploy (push) Has been cancelled
Some checks failed
deploy / deploy (push) Has been cancelled
- Add Site context for managing site-wide content (social links, nav items, announcement bar, footer content) - Add SocialLink schema with URL normalization and platform auto-detection supporting 40+ platforms via host and 25+ via URI scheme - Add NavItem schema for header/footer navigation (editor UI coming next) - Add SiteEditor component with collapsible sections for each content type - Wire social links card block and footer to use database data - Filter empty URLs from display in shop components - Add DetailsPreserver hook to preserve collapsible section state - Add comprehensive tests for Site context and SocialLink functions - Remove unused helper functions from onboarding to fix compiler warnings - Move sync_edit_url_param helper to group handle_editor_event clauses Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@ defmodule BerrypodWeb.ThemeHook do
|
||||
|
||||
import Phoenix.Component, only: [assign: 3]
|
||||
|
||||
alias Berrypod.{Products, Settings, Media}
|
||||
alias Berrypod.{Products, Settings, Site, Media}
|
||||
alias Berrypod.Theme.{CSSCache, CSSGenerator}
|
||||
|
||||
@default_header_nav [
|
||||
@@ -67,8 +67,12 @@ 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))
|
||||
|> assign(:header_nav_items, load_header_nav())
|
||||
|> assign(:footer_nav_items, load_footer_nav())
|
||||
|> assign(:social_links, Site.social_links_for_shop())
|
||||
|> assign(:announcement_text, Site.announcement_text())
|
||||
|> assign(:announcement_link, Site.announcement_link())
|
||||
|> assign(:announcement_style, Site.announcement_style())
|
||||
|
||||
{:cont, socket}
|
||||
end
|
||||
@@ -87,10 +91,24 @@ defmodule BerrypodWeb.ThemeHook do
|
||||
end
|
||||
end
|
||||
|
||||
defp load_nav(key, default) do
|
||||
case Settings.get_setting(key) do
|
||||
items when is_list(items) -> items
|
||||
_ -> default
|
||||
end
|
||||
defp load_header_nav do
|
||||
items = Site.nav_items_for_shop("header")
|
||||
if items == [], do: @default_header_nav, else: add_active_slugs(items)
|
||||
end
|
||||
|
||||
defp load_footer_nav do
|
||||
items = Site.nav_items_for_shop("footer")
|
||||
if items == [], do: @default_footer_nav, else: items
|
||||
end
|
||||
|
||||
# Add active_slugs for Shop nav item to highlight on collection and pdp pages
|
||||
defp add_active_slugs(items) do
|
||||
Enum.map(items, fn item ->
|
||||
if item["slug"] == "collection" do
|
||||
Map.put(item, "active_slugs", ["collection", "pdp"])
|
||||
else
|
||||
item
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user