Assign active_tab in handle_params to handle live patches

This commit is contained in:
Chris McCord 2021-11-23 09:34:27 -05:00
parent 62e00dc447
commit 7f9b7c5f9a

View file

@ -5,6 +5,13 @@ defmodule LiveBeatsWeb.Nav do
alias LiveBeatsWeb.{ProfileLive, SettingsLive} alias LiveBeatsWeb.{ProfileLive, SettingsLive}
def on_mount(:default, _params, _session, socket) do def on_mount(:default, _params, _session, socket) do
{:cont,
socket
|> assign(active_users: MediaLibrary.list_active_profiles(limit: 20))
|> attach_hook(:active_tab, :handle_params, &handle_active_tab_params/3)}
end
defp handle_active_tab_params(_params, _url, socket) do
active_tab = active_tab =
case {socket.view, socket.assigns.live_action} do case {socket.view, socket.assigns.live_action} do
{ProfileLive, _} -> :profile {ProfileLive, _} -> :profile
@ -12,10 +19,6 @@ defmodule LiveBeatsWeb.Nav do
{_, _} -> nil {_, _} -> nil
end end
{:cont, {:cont, assign(socket, active_tab: active_tab)}
assign(socket,
active_users: MediaLibrary.list_active_profiles(limit: 20),
active_tab: active_tab
)}
end end
end end