* Increase efficiency and fix pagination offset issue Right now we filter recently aggregated notifications at runtime, which worked before when there was no pagination, but now filtering is not a good idea combined with offset pagination because it throws off the calculations. The filtering should be done in the SQL query before paginating, which is what we've switched to. I added a bunch of scopes to make the code clearer as well. To avoid nesting tags I've also updated the HTML and the JS logic to insert it in the right place. * Add explanation for hiding the load more button for new users
26 lines
1.2 KiB
Text
26 lines
1.2 KiB
Text
<% @notifications.each do |notification| %>
|
|
<div
|
|
class="single-article single-article-small-pic single-notification <%= "unseen" unless notification.read? %>"
|
|
data-notification-id="<%= notification.id %>">
|
|
<%= render notification.notifiable_type.downcase.to_s, notification: notification %>
|
|
</div>
|
|
<% rescue => e %>
|
|
<% logger.error("Notification error - #{e.message} - #{notification.id}") %>
|
|
|
|
<div class="small-pic">
|
|
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LnVw15KE--/c_fill,f_auto,fl_progressive,h_90,q_auto,w_90/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg"
|
|
alt="Sloan, the sloth mascot">
|
|
</div>
|
|
<div class="content notification-content comment-content">
|
|
An error occurred! This has been logged and we're tracking it.
|
|
<br>
|
|
If you see too many of these, please report it to <a href="mailto:yo@dev.to">yo@dev.to</a>!
|
|
</div>
|
|
<% end %>
|
|
|
|
<% if @notifications.any? %>
|
|
<% sub_path = params[:org_id].present? ? "#{params[:filter]}/#{params[:org_id]}" : params[:filter].to_s %>
|
|
<div
|
|
class="notifications-paginator"
|
|
data-pagination-path="/notifications/<%= sub_path %>?offset=<%= @notifications.last.id %>"></div>
|
|
<% end %>
|