Files
grecia/app/components/layout/notification_item_component.rb
Javi Martín fb88e0b77c Fix number of new notifications
We were displaying the total number of notifications with a message "You
have N unread notifications", but were using the total number of
notifications instead of the unread ones.
2021-02-18 14:45:48 +01:00

34 lines
674 B
Ruby

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