include unread count in tooltip

This commit is contained in:
Devin Howard 2016-12-08 14:39:41 -05:00
parent 09a8e2ae67
commit 93af2ec84e
4 changed files with 7 additions and 16 deletions

View file

@ -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

View file

@ -3,7 +3,7 @@
<%= yield(:mobile_title) %>
</div>
<div id="menu_icon">
<% if user_has_unread_notifications? %>
<% if user_unread_notification_count > 0 %>
<div class="unread-notifications-dot"></div>
<% end %>
</div>
@ -55,7 +55,7 @@
</li>
<li class="notifications">
<%= link_to "Notifications", notifications_path %>
<% if user_has_unread_notifications? %>
<% if user_unread_notification_count > 0 %>
<div class="unread-notifications-dot"></div>
<% end %>
</li>

View file

@ -76,11 +76,11 @@
</script>
<% if current_user.present? %>
<span id="notification_icon">
<%= 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 %>
<div class="tooltipsUnder">
Notifications
Notifications (<%= user_unread_notification_count %> unread)
</div>
<% if user_has_unread_notifications? %>
<% if user_unread_notification_count > 0 %>
<div class="unread-notifications-dot"></div>
<% end %>
<% end %>

View file

@ -20,7 +20,7 @@ class NotificationIcon extends Component {
return (
<a className={linkClasses} href="/notifications">
<div className="tooltipsUnder">
Notifications
Notifications ({this.props.unreadNotificationsCount} unread)
</div>
{this.props.unreadNotificationsCount === 0 ? null : (
<div className="unread-notifications-dot"></div>