From 5e3149ad8e11f309c5fead8b049f0fd4f203b158 Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Tue, 23 Nov 2021 22:06:48 -0500 Subject: [PATCH] Only active tab user's own profile --- lib/live_beats_web/live/nav.ex | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/live_beats_web/live/nav.ex b/lib/live_beats_web/live/nav.ex index 7baa629..a32a04a 100644 --- a/lib/live_beats_web/live/nav.ex +++ b/lib/live_beats_web/live/nav.ex @@ -11,14 +11,27 @@ defmodule LiveBeatsWeb.Nav do |> attach_hook(:active_tab, :handle_params, &handle_active_tab_params/3)} end - defp handle_active_tab_params(_params, _url, socket) do + defp handle_active_tab_params(params, _url, socket) do active_tab = case {socket.view, socket.assigns.live_action} do - {ProfileLive, _} -> :profile - {SettingsLive, _} -> :settings - {_, _} -> nil + {ProfileLive, _} -> + if params["profile_username"] == current_user_profile_userame(socket) do + :profile + end + + {SettingsLive, _} -> + :settings + + {_, _} -> + nil end {:cont, assign(socket, active_tab: active_tab)} end + + defp current_user_profile_userame(socket) do + if user = socket.assigns.current_user do + user.username + end + end end