From 7f9b7c5f9a122adda0d31cf8038be4f78e91d6d2 Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Tue, 23 Nov 2021 09:34:27 -0500 Subject: [PATCH] Assign active_tab in handle_params to handle live patches --- lib/live_beats_web/live/nav.ex | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/live_beats_web/live/nav.ex b/lib/live_beats_web/live/nav.ex index 02a5426..7baa629 100644 --- a/lib/live_beats_web/live/nav.ex +++ b/lib/live_beats_web/live/nav.ex @@ -5,6 +5,13 @@ defmodule LiveBeatsWeb.Nav do alias LiveBeatsWeb.{ProfileLive, SettingsLive} 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 = case {socket.view, socket.assigns.live_action} do {ProfileLive, _} -> :profile @@ -12,10 +19,6 @@ defmodule LiveBeatsWeb.Nav do {_, _} -> nil end - {:cont, - assign(socket, - active_users: MediaLibrary.list_active_profiles(limit: 20), - active_tab: active_tab - )} + {:cont, assign(socket, active_tab: active_tab)} end end