[Posts] Add an approximate result counter (#903)

This commit is contained in:
Cinder 2025-02-11 22:25:46 -08:00 committed by GitHub
parent 6c95fdd8e3
commit ac38fd11e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 0 deletions

View File

@ -1,6 +1,29 @@
# frozen_string_literal: true # frozen_string_literal: true
module PaginationHelper module PaginationHelper
def approximate_count(records)
return "" if records.pagination_mode != :numbered
if records.total_pages > records.max_numbered_pages
pages = records.max_numbered_pages
schar = "over "
count = pages * records.records_per_page
title = "Over #{count} results found.\nActual result count may be much larger."
else
pages = records.total_pages
schar = "~"
count = pages * records.records_per_page
title = "Approximately #{count} results found.\nActual result count may differ."
end
tag.span(class: "approximate-count", title: title, data: { count: count, pages: pages, per: records.max_numbered_pages }) do
concat schar
concat number_to_human(count, precision: 2, format: "%n%u", units: { thousand: "k" })
concat " "
concat "result".pluralize(count)
end
end
def sequential_paginator(records) def sequential_paginator(records)
tag.nav(class: "pagination sequential", aria: { label: "Pagination" }) do tag.nav(class: "pagination sequential", aria: { label: "Pagination" }) do
return "" if records.try(:none?) return "" if records.try(:none?)

View File

@ -7,6 +7,7 @@
// Features // Features
@import "index/partials/mode_menu"; @import "index/partials/mode_menu";
@import "index/partials/wiki_excerpt"; @import "index/partials/wiki_excerpt";
@import "index/partials/stats";
@include window-larger-than(50rem) { @include window-larger-than(50rem) {
@include with-setting("fullscreen", "true") { @include with-setting("fullscreen", "true") {

View File

@ -0,0 +1,13 @@
.posts-index-stats {
display: flex;
justify-content: end;
margin: -0.5rem 0rem 0.25rem;
font-size: 0.75rem;
line-height: 0.75rem;
color: #fffa;
font-family: monospace;
& > span { cursor: help; }
}

View File

@ -24,6 +24,7 @@
<div class="content"> <div class="content">
<%= render "ads/leaderboard", tag_string: @post_set.ad_tag_string %> <%= render "ads/leaderboard", tag_string: @post_set.ad_tag_string %>
<%= render "posts/partials/index/edit" %> <%= render "posts/partials/index/edit" %>
<%= render "posts/partials/index/stats", :post_set => @post_set %>
<%= render "posts/partials/index/posts", :post_set => @post_set %> <%= render "posts/partials/index/posts", :post_set => @post_set %>
</div> </div>

View File

@ -0,0 +1,3 @@
<div class="posts-index-stats">
<%= approximate_count(post_set.posts) %>
</div>