Skip to content

Commit d6d4183

Browse files
authored
Tweak tag page for simpler pagination (forem#22739)
* Tweak tag page for simpler pagination * Fix spec * fix spec
1 parent ab4601a commit d6d4183

File tree

7 files changed

+46
-40
lines changed

7 files changed

+46
-40
lines changed

app/assets/javascripts/initializers/initScrolling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ function checkIfNearBottomOfPage() {
574574
function initScrolling() {
575575
var elCheck = document.getElementById('index-container');
576576

577-
if (elCheck) {
577+
if (elCheck && elCheck.dataset.disableInfiniteScroll !== 'true') {
578578
initScrolling.called = true;
579579
checkIfNearBottomOfPage();
580580
}

app/controllers/stories/tagged_articles_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Stories
22
class TaggedArticlesController < ApplicationController
33
before_action :set_cache_control_headers, only: :index
44

5-
SIGNED_OUT_RECORD_COUNT = 25
5+
SIGNED_OUT_RECORD_COUNT = 15
66

77
rescue_from ArgumentError, with: :bad_request
88

app/models/article.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def self.average_score
539539
end
540540
end
541541

542-
def self.seo_boostable(tag = nil, time_ago = 18.days.ago)
542+
def self.seo_boostable(tag = nil, time_ago = 18.days.ago, limit: 20)
543543
# Time ago sometimes returns this phrase instead of a date
544544
time_ago = 5.days.ago if time_ago == "latest"
545545

@@ -550,7 +550,7 @@ def self.seo_boostable(tag = nil, time_ago = 18.days.ago)
550550
.order(organic_page_views_past_month_count: :desc)
551551
.where("score > ?", 8)
552552
.where("published_at > ?", time_ago)
553-
.limit(20)
553+
.limit(limit)
554554

555555
fields = %i[path title comments_count created_at]
556556
if tag

app/views/stories/tagged_articles/_sidebar.html.erb

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% cache "tag-sidebar-#{@tag.name}-#{@tag&.updated_at}-#{user_signed_in?}-#{@page}", expires_in: 72.hours do %>
22
<div id="sidebar-wrapper-left" class="sidebar-wrapper sidebar-wrapper-left">
33
<div class="sidebar-bg" id="sidebar-bg-left"></div>
4-
<aside class="side-bar">
4+
<aside class="side-bar fs-s">
55
<% if @tag %>
66
<%= application_policy_content_tag("div", record: Article, query: :create?, class: "widget") do %>
77
<a class="crayons-btn crayons-btn--s" href="/new/<%= @tag.name %>">
@@ -11,19 +11,19 @@
1111
<% if @tag.rules_html.present? %>
1212
<div class="widget">
1313
<header>
14-
<h4><%= t("views.tags.sidebar.guidelines") %></h4>
14+
<h4 class="fs-base fw-medium"><%= t("views.tags.sidebar.guidelines") %></h4>
1515
</header>
16-
<div class="widget-body">
16+
<div class="widget-body fs-s">
1717
<%= sanitize @tag.rules_html %>
1818
</div>
1919
</div>
2020
<% end %>
2121
<% if @tag.wiki_body_html.present? %>
2222
<div class="widget">
2323
<header>
24-
<h4><%= t("views.tags.sidebar.about", tag: @tag.name) %></h4>
24+
<h4 class="fs-base fw-medium"><%= t("views.tags.sidebar.about", tag: @tag.name) %></h4>
2525
</header>
26-
<div class="widget-body">
26+
<div class="widget-body fs-s">
2727
<%= sanitize @tag.wiki_body_html %>
2828
</div>
2929
</div>
@@ -32,9 +32,9 @@
3232
<% if user_signed_in? && @moderators.present? %>
3333
<div class="widget">
3434
<header>
35-
<h4><%= t("views.tags.sidebar.mods") %></h4>
35+
<h4 class="fs-base fw-medium"><%= t("views.tags.sidebar.mods") %></h4>
3636
</header>
37-
<div class="widget-body">
37+
<div class="widget-body fs-s">
3838
<% @moderators.each do |user| %>
3939
<div class="widget-user-pic">
4040
<a href="/<%= user.username %>" title="<%= user.username %>">
@@ -74,28 +74,26 @@
7474
<%= t("views.tags.sidebar.moderate") %>
7575
</a>
7676
</div>
77-
<% else %>
78-
<% number_of_pages = (@num_published_articles.to_f / @number_of_articles).ceil %>
77+
<% elsif @tag.supported? %>
78+
<% number_of_pages = [(@num_published_articles.to_f / @number_of_articles).ceil, 1].max %>
7979
<% range = number_of_pages < 10 || @page < 4 ? 1..[number_of_pages, 9].min : [@page - 3, 1].max..[@page + 5, number_of_pages].min %>
80-
<% if number_of_pages > 1 %>
81-
<hr />
82-
<div class="olderposts-header"><%= t("views.tags.sidebar.older", tag: @tag.name) %></div>
83-
<div class="olderposts-links">
84-
<% range.each do |n| %>
85-
<% if @page == n %>
86-
<span class="olderposts-pagenumber"><%= n %></span>
87-
<% else %>
88-
<a href="<%= tag_url(@tag, n) %>" class="olderposts-pagenumber"><%= n %></a>
89-
<% end %>
80+
<hr />
81+
<div class="olderposts-header fs-base fw-medium"><%= t("views.tags.sidebar.older", tag: @tag.name) %></div>
82+
<div class="olderposts-links">
83+
<% range.each do |n| %>
84+
<% if @page == n %>
85+
<span class="olderposts-pagenumber"><%= n %></span>
86+
<% else %>
87+
<a href="<%= tag_url(@tag, n) %>" class="olderposts-pagenumber"><%= n %></a>
9088
<% end %>
91-
<% if @page == 1 && number_of_pages > 100 %>
92-
<div>
93-
<a href="<%= tag_url(@tag, 75) %>" class="olderposts-pagenumber">75</a>
94-
<a href="<%= tag_url(@tag, number_of_pages) %>" class="olderposts-pagenumber"><%= number_of_pages %></a>
95-
</div>
96-
<% end %>
97-
</div>
98-
<% end %>
89+
<% end %>
90+
<% if @page == 1 && number_of_pages > 100 %>
91+
<div>
92+
<a href="<%= tag_url(@tag, 75) %>" class="olderposts-pagenumber">75</a>
93+
<a href="<%= tag_url(@tag, number_of_pages) %>" class="olderposts-pagenumber"><%= number_of_pages %></a>
94+
</div>
95+
<% end %>
96+
</div>
9997
<% end %>
10098
</div>
10199
</aside>

app/views/stories/tagged_articles/_sidebar_additional.html.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<% if @page == 1 %>
22
<div id="sidebar-wrapper-right" class="sidebar-wrapper sidebar-wrapper-right">
33
<div class="sidebar-bg" id="sidebar-bg-right"></div>
4-
<aside class="side-bar sidebar-additional showing" id="sidebar-additional">
4+
<aside class="side-bar sidebar-additional showing fs-s" id="sidebar-additional">
55
<% active_threads = active_threads(tags: [@tag.name, "discuss"], time_ago: Timeframe.datetime(params[:timeframe])) %>
66
<% if user_signed_in? && active_threads.present? %>
77
<div class="widget">
88
<header>
9-
<h4><%= t("views.stories.discuss") %></h4>
9+
<h4 class="fs-base fw-medium"><%= t("views.stories.discuss") %></h4>
1010
</header>
11-
<div class="widget-body">
11+
<div class="widget-body fs-s">
1212
<div class="widget-link-list">
1313
<%= render partial: "articles/widget_list_item", collection: active_threads, as: :plucked_article, locals: { show_comment_count: true } %>
1414
</div>
@@ -20,14 +20,14 @@
2020
<div id="sidebarWidget__pack" data-tag-info="<%= @tag.attributes.slice("id", "text_color_hex", "bg_color_hex", "name").to_json %>">
2121
</div>
2222
<% else %>
23-
<% cache("seo-boostable-posts-for-tag-#{@tag.name}-#{params[:timeframe]}-#{RequestStore.store[:subforem_id]}", expires_in: 18.hours) do %>
24-
<% boostable_posts = Article.from_subforem.seo_boostable(@tag.name, Timeframe.datetime(params[:timeframe])) %>
23+
<% cache("seo-boostable-posts-for-tag-#{@tag.name}-#{params[:timeframe]}-30-#{RequestStore.store[:subforem_id]}", expires_in: 18.hours) do %>
24+
<% boostable_posts = Article.from_subforem.seo_boostable(@tag.name, Timeframe.datetime(params[:timeframe]), limit: 25) %>
2525
<% if boostable_posts.present? %>
2626
<div class="widget">
2727
<header>
28-
<h4><%= t("views.main.side.trend") %></h4>
28+
<h4 class="fs-base fw-medium"><%= t("views.main.side.trend") %></h4>
2929
</header>
30-
<div class="widget-body">
30+
<div class="widget-body fs-s">
3131
<div class="widget-link-list">
3232
<%= render partial: "articles/widget_list_item", collection: boostable_posts, as: :plucked_article, locals: { show_comment_count: false } %>
3333
</div>

app/views/stories/tagged_articles/index.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
data-params="<%= params.merge(sort_by: "hotness_score", sort_direction: "desc").to_json(only: %i[tag username sort_by sort_direction]) %>" data-which=""
5151
data-tag="<%= @tag.name %>"
5252
data-feed="<%= params[:timeframe] || "base-feed" %>"
53+
data-disable-infinite-scroll="<%= (!user_signed_in?).to_s %>"
5354
data-requires-approval="<%= @tag.requires_approval %>"
5455
data-articles-since="<%= Timeframe.datetime_iso8601(params[:timeframe]) %>">
5556
<%= render "stories/tagged_articles/sidebar" %>
@@ -128,9 +129,16 @@
128129
<%= render "stories/tagged_articles/main_feed" %>
129130
<% end %>
130131
</div>
132+
<% if !user_signed_in? && @stories.present? %>
133+
<div class="crayons-notice mt-4" aria-live="polite">
134+
<%= t("views.stories.sort.signin_html", path: subforem_aware_sign_up_url(sign_up_path(signup_subforem: RequestStore.store[:subforem_id]))) %>
135+
</div>
136+
<% end %>
137+
<% if user_signed_in? %>
131138
<div class="loading-articles" id="loading-articles">
132139
<%= t("core.loading") %>
133140
</div>
141+
<% end %>
134142
</main>
135143
<%= render "stories/tagged_articles/sidebar_additional" %>
136144
</div>

spec/requests/stories/tagged_articles_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ def renders_pagination
231231
expect(response.body).to include('<span class="olderposts-pagenumber">')
232232
end
233233

234-
it "renders tag index without pagination when not needed" do
234+
it "renders tag index with pagination for supported tags" do
235235
get "/t/#{tag.name}"
236236

237-
expect(response.body).not_to include('<span class="olderposts-pagenumber">')
237+
expect(response.body).to include('<span class="olderposts-pagenumber">')
238238
end
239239

240240
it "does not include sidebar for page tag" do

0 commit comments

Comments
 (0)