docbrown/app/views/sidebars/_homepage_content.html.erb
Julianna Tetreault af5a391429
Part 2: Shows Relevant Posts in Homepage Sidebar (#12942) [deploy]
* Adjust active_threads class method to display posts in homepage sidebar

* WIP: add specs around active_threads class method

* Uses newer AR query syntax in Article#active_threads

* WIP: Updates article_spec.rb to get tests passing

* WIP: Adjust test to return articles that dont fall into constraints

* Adjusts spec to update articles properly

* Adjust article.update_columns to match initial article columns

* Extracts .active_threads into a query object and removes class method
 - Removes class method from Article model
 - Removes class method tests from article_spec.rb
 - Adds Articles::ActiveThreadsQuery to app/queries/articles
 - Adds active_threads_query_spec.rb to spec/queries/articles
 - Replaces Article.active_threads with Articles::ActiveThreadsQuery
in _homepage_content.html.erb and _sidebar_activity.html.erb
 - General code clean up

* Rename number to count in Articles::ActiveThreadsQuery

* WIP new specs

* Update spec

* Repleaces let! with before block to appease rubocop

* Refactors Articles::ActiveThreadsQuery#call per PR review suggestion

* Calls Articles::ActiveThreadsQuery within articles_helper instead of view

Co-authored-by: Mac Siri <krairit.siri@gmail.com>
2021-03-25 08:03:55 -06:00

87 lines
3.9 KiB
Text

<aside class="side-bar sidebar-additional showing grid gap-4" id="sidebar-additional">
<% cache(release_adjusted_cache_key("main-article-right-sidebar-discussions-#{params[:timeframe]}"), expires_in: (params[:timeframe].blank? ? 120 : 360).seconds) do %>
<% @sidebar_ad = DisplayAd.for_display("sidebar_right") %>
<% if @sidebar_ad %>
<div class="crayons-card crayons-card--secondary p-4 crayons-sponsorship-widget">
<%= @sidebar_ad.processed_html.html_safe %>
</div>
<% end %>
<%= render "articles/sidebar_campaign" if Campaign.current.show_in_sidebar? %>
<% @listings = Listing.where(published: true).select(:title, :classified_listing_category_id, :slug, :bumped_at) %>
<% if params[:timeframe].blank? && @listings.any? %>
<section class="crayons-card crayons-card--secondary">
<header class="crayons-card__header">
<h3 class="crayons-subtitle-2">Listings</h3>
<div class="crayons-card__actions">
<a href="/listings" class="crayons-link--branded fw-medium fs-s">See all</a>
</div>
</header>
<div>
<% @listings.order(bumped_at: :desc).limit(5).each do |listing| %>
<a class="crayons-link crayons-link--contentful" href="<%= listing.path %>">
<div><%= listing.title %></div>
<div class="crayons-link__secondary"><%= listing.category %></div>
</a>
<% end %>
<a class="crayons-link crayons-link--branded block align-center p-3 fw-medium fs-s w-100" href="/listings/new">Create a Listing</a>
</div>
</section>
<% end %>
<% SiteConfig.sidebar_tags.each do |tag| %>
<section class="crayons-card crayons-card--secondary">
<header class="crayons-card__header">
<h3 class="crayons-subtitle-2"><a href="/t/<%= tag %>" class="crayons-link">#<%= tag %></a></h3>
</header>
<div>
<% if tag == "help" %>
<% Article.active_help.limit(5).pluck(:path, :title, :comments_count, :created_at).each do |plucked_article| %>
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
<% end %>
<% else %>
<% active_threads(options: { tags: [tag], time_ago: Timeframe.datetime(params[:timeframe]), count: 5 }).each do |plucked_article| %>
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: true %>
<% end %>
<% end %>
</div>
</section>
<% end %>
<% end %>
<% unless user_signed_in? %>
<% cache("seo-boostable-posts-homepage-#{params[:timeframe]}", expires_in: 18.hours) do %>
<% boostable_posts = Article.seo_boostable(nil, Timeframe.datetime(params[:timeframe])) %>
<% if boostable_posts.present? %>
<section class="widget">
<header>
<h4>trending guides/resources</h4>
</header>
<div class="widget-body">
<div class="widget-link-list">
<% boostable_posts.each do |plucked_article| %>
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: false %>
<% end %>
</div>
</div>
</section>
<% end %>
<% recent_preamble_optimized_posts = Article.search_optimized(nil) %>
<% if params[:timeframe].blank? && recent_preamble_optimized_posts.present? %>
<section class="widget">
<header>
<h4>recently queried</h4>
</header>
<div class="widget-body">
<div class="widget-link-list">
<% recent_preamble_optimized_posts.each do |plucked_article| %>
<%= render "articles/widget_list_item", plucked_article: plucked_article, show_comment_count: false %>
<% end %>
</div>
</div>
</section>
<% end %>
<% end %>
<% end %>
</aside>