[deploy] Paginate /dashboard posts (#8868)

* Paginate /dashboard

* Fix awkward pagination
This commit is contained in:
Ben Halpern 2020-06-23 17:29:24 -04:00 committed by GitHub
parent 33b68d4b39
commit 2219366af6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 8 deletions

View file

@ -22,7 +22,11 @@ class DashboardsController < ApplicationController
@articles = target.articles.includes(:organization)
end
@reactions_count = @articles.sum(&:public_reactions_count)
@page_views_count = @articles.sum(&:page_views_count)
@articles = @articles.sorting(params[:sort]).decorate
@articles = Kaminari.paginate_array(@articles).page(params[:page]).per(50)
# Updates analytics in background if appropriate
update_analytics = @articles && SiteConfig.ga_fetch_rate < 50 # Rate limited, sometimes we throttle down

View file

@ -1,8 +1,8 @@
<% num_views = @articles.sum(&:page_views_count) %>
<% num_views = @page_views_count %>
<div class="dashboard-analytics-header-wrapper">
<div class="dashboard-analytics-header">
<span><%= number_with_delimiter(@articles.sum(&:public_reactions_count), delimeter: ",") %></span>
<span><%= number_with_delimiter(@reactions_count, delimeter: ",") %></span>
<div class="dashboard-analytics-sub-indicator">
<img src="<%= asset_path "emoji/emoji-one-heart.png" %>" alt="heart" />
<img src="<%= asset_path "emoji/emoji-one-unicorn.png" %>" alt="unicorn" />

View file

@ -100,10 +100,6 @@
<% elsif @user == article.user %>
<a href="<%= article.path %>/delete_confirm" data-no-instant class="crayons-btn crayons-btn--ghost-danger crayons-btn--s">Delete</a>
<% end %>
<% if @current_user_pro %>
<a href="<%= article.path %>/stats" class="crayons-btn crayons-btn--ghost crayons-btn--s">Stats</a>
<% end %>
<a href="<%= article.path %>/edit" class="crayons-btn crayons-btn--ghost crayons-btn--s">Edit</a>
<div class="js-dashboard-row-more relative inline-block">
@ -112,6 +108,9 @@
</button>
<div class="crayons-dropdown top-100 right-0 z-10 align-left js-dashboard-row-more-dropdown">
<% if @current_user_pro %>
<a href="<%= article.path %>/stats" class="crayons-link crayons-link--block w-100 border-0 bg-transparent">Stats</a>
<% end %>
<%= form_for(article, method: :patch, remote: true, authenticity_token: true, html: { "data-type": "json", class: "js-archive-toggle" }) do |f| %>
<%= f.hidden_field :archived, value: !article.archived %>

View file

@ -42,7 +42,7 @@
<a class="video-upload-cta cta" href="/listings/dashboard" data-no-instant>
Create/Manage Listings
</a>
<%= select_tag "dashhboard_sort", options_for_select(sort_options, params[:sort]), 'aria-label': 'Sort By' %>
<%= select_tag "dashhboard_sort", options_for_select(sort_options, params[:sort]), 'aria-label': "Sort By" %>
<% if @articles.any? {|article| article.archived } %>
<%= link_to "Show archived", "javascript:;", id: "toggleArchivedLink" %>
<% end %>
@ -64,7 +64,9 @@
<% end %>
</tbody>
</table>
<div class="mb-4 pl-3">
<%= paginate @articles, params: { i: nil } %>
</div>
<% else %>
<div class="no-articles">
<h3>This is where you can manage your posts, but you haven't written anything yet.</h3>

View file

@ -37,6 +37,18 @@ RSpec.describe "Dashboards", type: :request do
get "/dashboard"
expect(response.body).to include "Delete"
end
it "renders pagination if minimum amount of posts" do
create_list(:article, 52, user: user)
get "/dashboard"
expect(response.body).to include "pagination"
end
it "does not render pagination if less than one full page" do
create_list(:article, 3, user: user)
get "/dashboard"
expect(response.body).not_to include "pagination"
end
end
context "when logged in as a super admin" do