berrypod/lib/berrypod_web/admin_layout_hook.ex

24 lines
810 B
Elixir
Raw Normal View History

defmodule BerrypodWeb.AdminLayoutHook do
@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, "")
|> assign(:site_live, Berrypod.Settings.site_live?())
|> 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, Berrypod.Settings.site_live?())}
end)
{:cont, socket}
end
end