Skip to content

Commit a172696

Browse files
committed
Improve notifications dropdown behaviour
1 parent cafc0c2 commit a172696

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

app/assets/stylesheets/better_together/navigation.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,10 @@ table.nav-items-table tr.navigation_item_children > td > table {
188188
bottom: 0;
189189
z-index: 1000;
190190
}
191+
192+
.dropdown-menu-center {
193+
left: 50% !important;
194+
transform: translateX(-50%) !important;
195+
right: auto !important;
196+
}
197+

app/assets/stylesheets/better_together/notifications.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@
3535
position: relative;
3636
}
3737
}
38+
39+
#notification-list {
40+
#notification-header {
41+
display: flex;
42+
justify-content: space-between;
43+
align-items: center;
44+
}
45+
}

app/helpers/better_together/notifications_helper.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
module BetterTogether
44
# groups view logic related to notifications
55
module NotificationsHelper
6-
def unread_notification_count
7-
count = current_person.notifications.unread.size
6+
def unread_notifications?
7+
unread_notification_count > 0
8+
end
9+
10+
def unread_notification_counter
11+
count = unread_notification_count
812
return if count.zero?
913

1014
content_tag(:span, count, class: 'badge bg-primary rounded-pill position-absolute notification-badge',
1115
id: 'person_notification_count')
1216
end
1317

18+
def unread_notification_count
19+
return unless current_person
20+
21+
current_person.notifications.unread.size
22+
end
23+
1424
def recent_notifications
1525
current_person.notifications.joins(:event).order(created_at: :desc).limit(5)
1626
end
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
<li class="nav-item notifications dropdown" data-bs-toggle="tooltip" data-bs-placement="bottom" title="<%= t('navbar.notifications_tooltip') %>">
22
<a id="notification-icon" class="nav-link position-relative<%= ' active' if params[:controller].present? && url_for(controller: params[:controller], action: params[:action]) === notifications_path %>" href="<%= notifications_path %>" role="button" data-bs-toggle="dropdown" aria-expanded="false">
33
<i class="fa fa-bell"></i>
4-
<%= unread_notification_count %>
4+
<%= unread_notification_counter %>
55
</a>
6-
<ul id="notification-list" class="dropdown-menu dropdown-menu-end p-3" style="min-width: 25rem;" aria-labelledby="notification-icon">
6+
<ul id="notification-list" class="dropdown-menu dropdown-menu-center p-3 position-absolute" style="min-width: 25rem;" aria-labelledby="notification-icon">
7+
<li>
8+
<h5 id="notification-header">
9+
<%= link_to 'Notifications', notifications_url, class: 'text-decoration-none' %>
10+
<%= button_to t('better_together.notifications.mark_all_as_read'),
11+
mark_all_as_read_notifications_path,
12+
method: :post,
13+
class: 'btn btn-secondary btn-sm',
14+
id: 'mark_notifications_read',
15+
data: { turbo_stream: true } if unread_notifications? %>
16+
</h5>
17+
</li>
18+
<li><hr class="dropdown-divider"></li>
719
<%= render recent_notifications %>
820
</ul>
921
</li>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<li class="d-flex flex-column align-items-start mb-3 dropdown-item">
1717
<strong><%= current_user.email %></strong>
1818
</li>
19+
<li><hr class="dropdown-divider"></li>
1920
<li>
2021
<%= link_to t('navbar.my_profile'), person_my_profile_path(person_id: current_person.slug), class: "my-profile dropdown-item ", data: { identifier: 'my-profile' } %>
2122
</li>

0 commit comments

Comments
 (0)