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:
@@ -9,12 +9,13 @@ class PostsController < ApplicationController
|
||||
format.html { redirect_to(@post) }
|
||||
end
|
||||
elsif params[:random].to_s.truthy?
|
||||
post_set = PostSets::Post.new(params[:tags], params[:page], params[:limit], format: request.format.symbol, view: params[:view])
|
||||
post_set = PostSets::Post.new(params[:tags], params[:page], params[:limit], format: request.format.symbol)
|
||||
query = "#{post_set.normalized_query.to_s} random:#{post_set.per_page}".strip
|
||||
redirect_to posts_path(tags: query, page: params[:page], limit: params[:limit], format: request.format.symbol, view: params[:view], size: params[:size])
|
||||
redirect_to posts_path(tags: query, page: params[:page], limit: params[:limit], format: request.format.symbol)
|
||||
else
|
||||
tag_query = params[:tags] || params.dig(:post, :tags)
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], format: request.format.symbol, view: params[:view])
|
||||
@show_votes = (params[:show_votes].presence || cookies[:post_preview_show_votes].presence || "false").truthy?
|
||||
@post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], format: request.format.symbol, show_votes: @show_votes)
|
||||
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
||||
@posts = authorize @post_set.posts, policy_class: PostPolicy
|
||||
@post_set.log!
|
||||
@@ -56,6 +57,7 @@ class PostsController < ApplicationController
|
||||
def update
|
||||
@post = authorize Post.find(params[:id])
|
||||
@post.update(permitted_attributes(@post))
|
||||
@show_votes = (params[:show_votes].presence || cookies[:post_preview_show_votes].presence || "false").truthy?
|
||||
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
|
||||
respond_with_post_after_update(@post)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user