explore/posts/viewed: refactor post previews.

This commit is contained in:
evazion
2020-01-12 21:33:31 -06:00
parent 083ce75c10
commit 74ce866890
5 changed files with 4 additions and 76 deletions

View File

@@ -10,8 +10,7 @@ module Explore
end
def viewed
@post_set = PostSets::MostViewed.new(@date.to_s)
@posts = @post_set.posts
@posts = PostViewCountService.new.popular_posts(@date)
respond_with(@posts)
end

View File

@@ -1,17 +0,0 @@
module PostSets
class MostViewed < PostSets::Base
attr_reader :date
def initialize(date)
@date = date.blank? ? Date.today : Date.parse(date)
end
def posts
@posts ||= PostViewCountService.new.popular_posts(date)
end
def presenter
::PostSetPresenters::MostViewed.new(self)
end
end
end

View File

@@ -5,7 +5,7 @@ class PostViewCountService
def initialize
if !PostViewCountService.enabled?
raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.")
raise NotImplementedError.new("the Reportbooru service isn't configured. Post views are not available.")
end
end

View File

@@ -1,54 +0,0 @@
module PostSetPresenters
class MostViewed < Base
attr_accessor :post_set, :tag_set_presenter
delegate :posts, :date, :to => :post_set
def initialize(post_set)
@post_set = post_set
end
def prev_day
date - 1.day
end
def next_day
date + 1.day
end
def nav_links_for_scale(template)
html = []
html << '<span class="period">'
html << template.link_to(
"< Back".html_safe,
template.viewed_explore_posts_path(
:date => prev_day
),
:rel => "prev"
)
html << template.link_to(
date.to_s,
template.viewed_explore_posts_path(
:date => date
),
:class => "desc"
)
html << template.link_to(
"Next >".html_safe,
template.viewed_explore_posts_path(
:date => next_day
),
:rel => "next"
)
html << '</span>'
html.join("\n").html_safe
end
def nav_links(template)
html = []
html << '<p id="popular-nav-links">'
html << nav_links_for_scale(template)
html << '</p>'
html.join("\n").html_safe
end
end
end

View File

@@ -1,10 +1,10 @@
<div id="c-explore-posts">
<div id="a-viewed">
<h1>Most Viewed - <%= @post_set.presenter.date %></h1>
<h1>Most Viewed - <%= @date %></h1>
<%= render "posts/partials/common/inline_blacklist" %>
<%= @post_set.presenter.post_previews_html(self) %>
<%= post_previews_html(@posts) %>
<div class="paginator">
<menu>