Add pagination to searches

This commit is contained in:
Jorge Manrubia
2025-10-07 08:49:05 +02:00
parent 85907e2a4e
commit 4e6866bd2e
4 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ class SearchesController < ApplicationController
private
def perform_search
@search_results = Current.user.search(@query_terms).limit(50)
set_page_and_extract_portion_from Current.user.search(@query_terms)
@recent_search_queries = Current.user.search_queries.order(updated_at: :desc).limit(10)
end
end
@@ -1,5 +1,5 @@
<section class="cards cards--grid">
<%= with_automatic_pagination :cards_paginated_container, page do %>
<%= with_automatic_pagination :filtered_cards_paginated_container, page do %>
<%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { cacheable_preview_parts_for(card) } %>
<% end %>
</section>
+4 -2
View File
@@ -7,14 +7,16 @@
<section class="search">
<div class="search__results">
<% if search_results.none? %>
<% unless page.used? %>
<div class="search__empty">
No matches
</div>
<% end %>
<ul class="search__list">
<%= render partial: "searches/result", collection: search_results %>
<%= with_automatic_pagination :filtered_search_results, page do %>
<%= render partial: "searches/result", collection: page.records %>
<% end %>
</ul>
</div>
</section>
+1 -1
View File
@@ -2,6 +2,6 @@
<% if @card %>
<%= auto_submit_form_with url: card_path(@card), method: :get, data: { turbo_action: "advance", turbo_frame: "_top", search_redirect: true } %>
<% else %>
<%= render "results", search_results: @search_results %>
<%= render "results", page: @page %>
<% end %>
<% end %>