berrypod/lib/simpleshop_theme_web/admin_layout_hook.ex

20 lines
674 B
Elixir
Raw Normal View History

defmodule SimpleshopThemeWeb.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, "")
|> Phoenix.LiveView.attach_hook(:set_current_path, :handle_params, fn _params,
uri,
socket ->
{:cont, assign(socket, :current_path, URI.parse(uri).path)}
end)
{:cont, socket}
end
end