Skip to content

Commit a493271

Browse files
committed
Render up to 10 notifications in nav dropdown menu
1 parent 5061731 commit a493271

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

app/helpers/better_together/notifications_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ def unread_notification_count
99

1010
content_tag(:span, count, class: 'badge bg-primary rounded-pill position-absolute notification-badge')
1111
end
12+
13+
def recent_notifications
14+
current_person.notifications.order(created_at: :desc).limit(10)
15+
end
1216
end
1317
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- app/views/better_together/new_message_notifier/_notification.html.erb -->
22
<%= render layout: 'better_together/notifications/notification', locals: { notification: notification, notification_title: t('better_together.new_message_notifier.new_message', conversation_title: notification.conversation.title), notification_url: notification.url } do %>
33
<p class="mb-1 message-content">
4-
<strong><%= t('better_together.new_message_notifier.from_html', sender: (policy(notification.sender).show? ? link_to(notification.sender) : notification.sender)) %></strong><br>
5-
<%= notification.message.content.truncate(100) %>
4+
<strong><%= policy(notification.sender).show? ? link_to(notification.sender, notification.sender, class: 'text-decoration-none') : notification.sender %></strong><br>
5+
<%= notification.message.content.to_plain_text.truncate(100) %>
66
</p>
77
<% end %>

app/views/better_together/notifications/_notification.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!-- app/views/better_together/notifications/_notification.html.erb -->
22
<div id="<%= dom_id(notification) %>" class="notification list-group-item <%= 'list-group-item-action' unless notification.read_at %>" data-controller="better_together--notification" data-notification-mark-read-url-value="<%= mark_as_read_notification_path(notification) %>">
33
<div class="d-flex justify-content-between">
4-
<h5 class="mb-1">
4+
<h6 class="mb-1">
55
<% if notification_url.present? %>
6-
<%= link_to notification_title, notification_url %>
6+
<%= link_to notification_title, notification_url, class: 'text-decoration-none' %>
77
<% else %>
88
<%= notification_title %>
99
<% end %>
10-
</h5>
10+
</h6>
1111
<small class="text-muted"><%= t('better_together.notifications.time_ago', time: time_ago_in_words(notification.created_at)) %></small>
1212
</div>
1313
<%= yield if block_given? %> <!-- This will render the specific content from the notification type partial -->

app/views/layouts/better_together/_header.html.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@
3232

3333
<!-- User Auth Nav Item -->
3434
<% if user_signed_in? %>
35-
<li class="nav-item notifications" data-bs-toggle="tooltip" data-bs-placement="bottom" title="<%= t('navbar.notifications_tooltip') %>">
36-
<a class="nav-link position-relative<%= ' active' if url_for(controller: params[:controller], action: params[:action]) === notifications_path %>" href="<%= notifications_path %>">
35+
<li class="nav-item notifications dropdown" data-bs-toggle="tooltip" data-bs-placement="bottom" title="<%= t('navbar.notifications_tooltip') %>">
36+
<a id="notification-icon" class="nav-link position-relative<%= ' active' if url_for(controller: params[:controller], action: params[:action]) === notifications_path %>" href="<%= notifications_path %>" role="button" data-bs-toggle="dropdown" aria-expanded="false">
3737
<i class="fa fa-bell"></i>
3838
<%= unread_notification_count %>
3939
</a>
40+
<ul id="notification-list" class="dropdown-menu dropdown-menu-end p-3" style="min-width: 25rem;" aria-labelledby="notification-icon">
41+
<%= render recent_notifications %>
42+
</ul>
4043
</li>
4144

4245
<%= cache ['locale_switcher', request.fullpath, I18n.locale] do %>

0 commit comments

Comments
 (0)