Skip to content

Commit 0717445

Browse files
adds unread notification only when current user
1 parent 973caf2 commit 0717445

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/instagram_clone_web/live/header_nav_component.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ defmodule InstagramCloneWeb.HeaderNavComponent do
1818

1919
@impl true
2020
def update(assigns, socket) do
21-
current_user_id = assigns.current_user.id
22-
unread_notification? = Notifications.get_unread(current_user_id)
23-
2421
{:ok,
2522
socket
2623
|> assign(assigns)
27-
|> assign(unread_notifications?: unread_notification?)}
24+
|> assign(unread_notifications?: unread_notification?(assigns))}
25+
end
26+
27+
defp unread_notification?(assigns) do
28+
if assigns.current_user do
29+
Notifications.get_unread(assigns.current_user.id)
30+
else
31+
false
32+
end
2833
end
2934

3035
@impl true

0 commit comments

Comments
 (0)