Extract method to get the notifications link text

This commit is contained in:
Javi Martín
2021-02-15 23:45:57 +01:00
parent f11f2cd3dd
commit 5b6551f6d7
2 changed files with 13 additions and 14 deletions

View File

@@ -8,23 +8,12 @@
<% if user.notifications.unread.count > 0 %>
<span class="icon-circle" aria-hidden="true"></span>
<span class="icon-notification" aria-hidden="true"
title="<%= t("layouts.header.notification_item.new_notifications",
count: user.notifications_count) %>">
</span>
<span class="show-for-small-only">
<%= t("layouts.header.notification_item.new_notifications",
count: user.notifications_count) %>
</span>
<span class="icon-notification" aria-hidden="true" title="<%= text %>"></span>
<% else %>
<span class="icon-no-notification" aria-hidden="true"
title="<%= t("layouts.header.notification_item.no_notifications") %>">
</span>
<span class="show-for-small-only">
<%= t("layouts.header.notification_item.no_notifications") %>
</span>
<span class="icon-no-notification" aria-hidden="true" title="<%= text %>"></span>
<% end %>
<span class="show-for-small-only"><%= text %></span>
<% end %>
</li>
<% end %>

View File

@@ -4,4 +4,14 @@ class Layout::NotificationItemComponent < ApplicationComponent
def initialize(user)
@user = user
end
private
def text
if user.notifications.unread.count > 0
t("layouts.header.notification_item.new_notifications", count: user.notifications_count)
else
t("layouts.header.notification_item.no_notifications")
end
end
end