diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 8adb04b3c..76bd62974 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,6 +1,8 @@ class NotificationsController < ApplicationController + MAX_UNREAD_NOTIFICATIONS = 500 + def index - @unread = Current.user.notifications.unread.ordered.preloaded unless current_page_param + @unread = Current.user.notifications.unread.ordered.preloaded.limit(MAX_UNREAD_NOTIFICATIONS) unless current_page_param set_page_and_extract_portion_from Current.user.notifications.read.ordered.preloaded respond_to do |format| diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index eae50830b..70fee45b8 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -13,30 +13,8 @@
-
- <% if @unread.any? %> -
-

New for you

- <%= button_to "Mark all as read", bulk_reading_path, class: "btn txt-small", form: { data: { turbo: false } }, data: { action: "badge#clear" } %> -
- <% else %> -
- Nothing new for you. -
- <% end %> - -
- <%= render partial: "notifications/index/notification", collection: @unread, cached: true %> -
-
- -
-

Previously seen

- -
- <%= render partial: "notifications/index/notification", collection: @page.records, cached: true %> -
-
+ <%= render "notifications/index/unread_notifications", unread: @unread if @unread %> + <%= render "notifications/index/read_notifications", page: @page %>
<%= notifications_next_page_link(@page) if @page.records.any? %> diff --git a/app/views/notifications/index/_read_notifications.html.erb b/app/views/notifications/index/_read_notifications.html.erb new file mode 100644 index 000000000..c5e282237 --- /dev/null +++ b/app/views/notifications/index/_read_notifications.html.erb @@ -0,0 +1,7 @@ +
+

Previously seen

+ +
+ <%= render partial: "notifications/index/notification", collection: page.records, cached: true %> +
+
diff --git a/app/views/notifications/index/_unread_notifications.html.erb b/app/views/notifications/index/_unread_notifications.html.erb new file mode 100644 index 000000000..9a9898788 --- /dev/null +++ b/app/views/notifications/index/_unread_notifications.html.erb @@ -0,0 +1,25 @@ +
+ <% if unread.any? %> +
+

New for you

+ <%= button_to "Mark all as read", bulk_reading_path, class: "btn txt-small", form: { data: { turbo: false } }, data: { action: "badge#clear" } %> +
+ <% else %> +
+ Nothing new for you. +
+ <% end %> + +
+ <%= render partial: "notifications/index/notification", collection: unread, cached: true %> +
+ + <% if unread.any? %> + <% total_unread_count = Current.user.notifications.unread.count %> + <% if Current.user.notifications.unread.count > NotificationsController::MAX_UNREAD_NOTIFICATIONS %> +
+ Showing the <%= NotificationsController::MAX_UNREAD_NOTIFICATIONS %> most recent (<%= total_unread_count - NotificationsController::MAX_UNREAD_NOTIFICATIONS %> are hidden) +
+ <% end %> + <% end %> +