berrypod/lib/berrypod_web/admin_layout_hook.ex
jamey 64f083d271
All checks were successful
deploy / deploy (push) Successful in 1m31s
improve setup UX: password field, setup hook, checklist banners, theme tweaks
- add password field and required shop name to setup wizard
- extract SetupHook for DRY redirect to /setup when no admin exists
- add ?from=checklist param to checklist hrefs with contextual banner on
  email settings and theme pages for easy return to dashboard
- remove email warning banner from admin layout (checklist covers it)
- make email a required checklist item (no longer optional)
- add DevReset module for wiping dev data without restart
- rename "Theme Studio" to "Theme", drop subtitle
- lower theme editor side-by-side breakpoint from 64em to 48em
- clean up login/registration pages (remove dead registration_open code)
- fix settings.put_secret to invalidate cache after write

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 17:41:08 +00:00

55 lines
1.8 KiB
Elixir

defmodule BerrypodWeb.AdminLayoutHook do
@moduledoc """
LiveView on_mount hook that assigns the current path for admin sidebar navigation
and loads theme settings for the admin layout.
"""
import Phoenix.Component
alias Berrypod.{ActivityLog, Settings}
alias Berrypod.Theme.{CSSCache, CSSGenerator}
def on_mount(:assign_current_path, _params, _session, socket) do
theme_settings = Settings.get_theme_settings()
generated_css =
case CSSCache.get() do
{:ok, css} ->
css
:miss ->
css = CSSGenerator.generate(theme_settings, &BerrypodWeb.Endpoint.static_path/1)
CSSCache.put(css)
css
end
if Phoenix.LiveView.connected?(socket), do: ActivityLog.subscribe()
socket =
socket
|> assign(:current_path, "")
|> assign(:site_live, Settings.site_live?())
|> assign(:theme_settings, theme_settings)
|> assign(:site_name, Settings.site_name())
|> assign(:site_description, Settings.site_description())
|> assign(:generated_css, generated_css)
|> assign(:attention_count, ActivityLog.count_needing_attention())
|> Phoenix.LiveView.attach_hook(:set_current_path, :handle_params, fn _params,
uri,
socket ->
{:cont,
socket
|> assign(:current_path, URI.parse(uri).path)
|> assign(:site_live, Settings.site_live?())}
end)
|> Phoenix.LiveView.attach_hook(:update_attention_count, :handle_info, fn
{:new_activity, _entry}, socket ->
{:cont, assign(socket, :attention_count, ActivityLog.count_needing_attention())}
_other, socket ->
{:cont, socket}
end)
{:cont, socket}
end
end