Fix #4930: "Show scores" setting should be preserved

Make "show scores" setting persistent.

The setting is stored in a `post_preview_show_votes` cookie. This means
it's remembered on a per-device basis, but not on a per-account basis.
This is so users without an account can use the setting, and so you can
use different settings on desktop and mobile.

The `view=score` URL param has been replaced by `show_votes=true`. The
`show_votes` URL param overrides the `post_preview_show_votes` cookie.
This commit is contained in:
evazion
2021-12-09 15:40:22 -06:00
parent 3de93f556e
commit 7976d12cd0
6 changed files with 47 additions and 33 deletions

View File

@@ -7,17 +7,18 @@ module PostSets
MAX_PER_PAGE = 200
MAX_SIDEBAR_TAGS = 25
attr_reader :page, :format, :tag_string, :query, :normalized_query, :view
attr_reader :page, :format, :tag_string, :query, :normalized_query, :show_votes
delegate :post_count, to: :normalized_query
alias_method :show_votes?, :show_votes
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, format: "html", view: "simple")
def initialize(tags, page = 1, per_page = nil, user: CurrentUser.user, format: "html", show_votes: false)
@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
@page = page
@per_page = per_page
@format = format.to_s
@view = view.presence || "simple"
@show_votes = show_votes
end
def humanized_tag_string
@@ -126,10 +127,6 @@ module PostSets
end
end
def show_votes?
view == "score"
end
def includes
if show_votes?
[:media_asset, :vote_by_current_user]