votes: add vote buttons beneath thumbnails.
Add upvote and downvote buttons beneath thumbnails on the post index page. This is disabled by default. To enable it, click the "..." menu in the top right of the page, then click "Show scores". This is currently a per-search setting, not an account setting. If you enable it in one tab, it won't be enabled in other tabs.
This commit is contained in:
@@ -7,10 +7,10 @@ module PostSets
|
||||
MAX_PER_PAGE = 200
|
||||
MAX_SIDEBAR_TAGS = 25
|
||||
|
||||
attr_reader :page, :random, :format, :tag_string, :query, :normalized_query
|
||||
attr_reader :page, :random, :format, :tag_string, :query, :normalized_query, :view
|
||||
delegate :post_count, to: :normalized_query
|
||||
|
||||
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, random: false, format: "html")
|
||||
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, random: false, format: "html", view: "simple")
|
||||
@query = PostQueryBuilder.new(tags, user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?, hide_deleted_posts: user.hide_deleted_posts?)
|
||||
@normalized_query = query.normalized_query
|
||||
@tag_string = tags
|
||||
@@ -18,6 +18,7 @@ module PostSets
|
||||
@per_page = per_page
|
||||
@random = random.to_s.truthy?
|
||||
@format = format.to_s
|
||||
@view = view.presence || "simple"
|
||||
end
|
||||
|
||||
def humanized_tag_string
|
||||
@@ -107,7 +108,7 @@ module PostSets
|
||||
if is_random?
|
||||
get_random_posts.paginate(page, search_count: false, limit: per_page, max_limit: max_per_page).load
|
||||
else
|
||||
normalized_query.paginated_posts(page, includes: :media_asset, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
||||
normalized_query.paginated_posts(page, includes: includes, count: post_count, search_count: !post_count.nil?, limit: per_page, max_limit: max_per_page).load
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -139,6 +140,18 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
def show_votes?
|
||||
view == "score"
|
||||
end
|
||||
|
||||
def includes
|
||||
if show_votes?
|
||||
[:media_asset, :vote_by_current_user]
|
||||
else
|
||||
[:media_asset]
|
||||
end
|
||||
end
|
||||
|
||||
def search_stats
|
||||
{
|
||||
query: normalized_query.to_s,
|
||||
|
||||
Reference in New Issue
Block a user