From 5b6551f6d7139d2f399fa1dee8ff34775de0bb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 15 Feb 2021 23:45:57 +0100 Subject: [PATCH] Extract method to get the notifications link text --- .../layout/notification_item_component.html.erb | 17 +++-------------- .../layout/notification_item_component.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/components/layout/notification_item_component.html.erb b/app/components/layout/notification_item_component.html.erb index 954b60420..2fbae2250 100644 --- a/app/components/layout/notification_item_component.html.erb +++ b/app/components/layout/notification_item_component.html.erb @@ -8,23 +8,12 @@ <% 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 %> + <%= text %> <% end %> <% end %> diff --git a/app/components/layout/notification_item_component.rb b/app/components/layout/notification_item_component.rb index 62952be1c..37be31de1 100644 --- a/app/components/layout/notification_item_component.rb +++ b/app/components/layout/notification_item_component.rb @@ -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