Simplify code to display text of new notifications

We couldn't do this refactoring earlier because we weren't using the
unread notifications count. This was fixed in the previous commit.
This commit is contained in:
Javi Martín
2021-02-16 01:26:57 +01:00
parent fb88e0b77c
commit e266e0e0e2
3 changed files with 4 additions and 12 deletions

View File

@@ -8,25 +8,17 @@ class Layout::NotificationItemComponent < ApplicationComponent
private private
def text def text
if unread_notifications? t("layouts.header.notification_item.new_notifications", count: unread_notifications.count)
t("layouts.header.notification_item.new_notifications", count: unread_notifications.count)
else
t("layouts.header.notification_item.no_notifications")
end
end end
def notifications_class def notifications_class
if unread_notifications? if unread_notifications.count > 0
"unread-notifications" "unread-notifications"
else else
"no-notifications" "no-notifications"
end end
end end
def unread_notifications?
unread_notifications.count > 0
end
def unread_notifications def unread_notifications
user.notifications.unread user.notifications.unread
end end

View File

@@ -249,8 +249,8 @@ en:
new_notifications: new_notifications:
one: You have a new notification one: You have a new notification
other: You have %{count} new notifications other: You have %{count} new notifications
zero: "You don't have new notifications"
notifications: Notifications notifications: Notifications
no_notifications: "You don't have new notifications"
sdg: "SDG" sdg: "SDG"
notifications: notifications:
index: index:

View File

@@ -249,8 +249,8 @@ es:
new_notifications: new_notifications:
one: Tienes una nueva notificación one: Tienes una nueva notificación
other: Tienes %{count} notificaciones nuevas other: Tienes %{count} notificaciones nuevas
zero: "No tienes notificaciones nuevas"
notifications: Notificaciones notifications: Notificaciones
no_notifications: "No tienes notificaciones nuevas"
sdg: "ODS" sdg: "ODS"
notifications: notifications:
index: index: