diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index cc121cbe..45a5d565 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -38,18 +38,9 @@ module ApplicationHelper
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
end
- def user_has_unread_notifications?
- return @user_has_unread_notifications unless @user_has_unread_notifications.nil?
- return (@user_has_unread_notifications = false) if current_user.nil?
- current_user.mailboxer_notification_receipts.each do |receipt|
- return (@user_has_unread_notifications = true) if receipt.is_read == false
- end
- @user_has_unread_notifications = false
- end
-
def user_unread_notification_count
return 0 if current_user.nil?
- current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
+ @user_unread_notification_count ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
receipt.is_read ? total : total + 1
end
end
diff --git a/app/views/layouts/_mobilemenu.html.erb b/app/views/layouts/_mobilemenu.html.erb
index c557f516..5ef3a66d 100644
--- a/app/views/layouts/_mobilemenu.html.erb
+++ b/app/views/layouts/_mobilemenu.html.erb
@@ -3,7 +3,7 @@
<%= yield(:mobile_title) %>
@@ -55,7 +55,7 @@
<%= link_to "Notifications", notifications_path %>
- <% if user_has_unread_notifications? %>
+ <% if user_unread_notification_count > 0 %>
<% end %>
diff --git a/app/views/layouts/_upperelements.html.erb b/app/views/layouts/_upperelements.html.erb
index 515bfcd4..1f499615 100644
--- a/app/views/layouts/_upperelements.html.erb
+++ b/app/views/layouts/_upperelements.html.erb
@@ -76,11 +76,11 @@
<% if current_user.present? %>
- <%= link_to notifications_path, class: "notificationsIcon upperRightEl upperRightIcon #{user_has_unread_notifications? ? 'unread' : 'read'}" do %>
+ <%= link_to notifications_path, class: "notificationsIcon upperRightEl upperRightIcon #{user_unread_notification_count > 0 ? 'unread' : 'read'}" do %>
- Notifications
+ Notifications (<%= user_unread_notification_count %> unread)
- <% if user_has_unread_notifications? %>
+ <% if user_unread_notification_count > 0 %>
<% end %>
<% end %>
diff --git a/frontend/src/components/NotificationIcon.js b/frontend/src/components/NotificationIcon.js
index b886f557..98782a75 100644
--- a/frontend/src/components/NotificationIcon.js
+++ b/frontend/src/components/NotificationIcon.js
@@ -20,7 +20,7 @@ class NotificationIcon extends Component {
return (
- Notifications
+ Notifications ({this.props.unreadNotificationsCount} unread)
{this.props.unreadNotificationsCount === 0 ? null : (