2026-02-18 21:23:15 +00:00
|
|
|
defmodule BerrypodWeb.AdminLayoutHook do
|
2026-02-12 08:35:22 +00:00
|
|
|
@moduledoc """
|
|
|
|
|
LiveView on_mount hook that assigns the current path for admin sidebar navigation.
|
|
|
|
|
"""
|
|
|
|
|
import Phoenix.Component
|
|
|
|
|
|
|
|
|
|
def on_mount(:assign_current_path, _params, _session, socket) do
|
|
|
|
|
socket =
|
|
|
|
|
socket
|
|
|
|
|
|> assign(:current_path, "")
|
2026-02-18 23:55:42 +00:00
|
|
|
|> assign(:site_live, Berrypod.Settings.site_live?())
|
2026-02-12 08:35:22 +00:00
|
|
|
|> Phoenix.LiveView.attach_hook(:set_current_path, :handle_params, fn _params,
|
|
|
|
|
uri,
|
|
|
|
|
socket ->
|
2026-02-18 23:55:42 +00:00
|
|
|
{:cont,
|
|
|
|
|
socket
|
|
|
|
|
|> assign(:current_path, URI.parse(uri).path)
|
|
|
|
|
|> assign(:site_live, Berrypod.Settings.site_live?())}
|
2026-02-12 08:35:22 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
{:cont, socket}
|
|
|
|
|
end
|
|
|
|
|
end
|