posts: make thumbnail size setting persistent.

Make setting the thumbnail size persistent.

The setting is stored in a `post_preview_size` cookie. This cookie can
be overridden by the `size` URL param, like so:

  https://danbooru.donmai.us/posts?tags=touhou&size=180

The `size` param is mainly for testing different sizes without setting a cookie.
This commit is contained in:
evazion
2021-12-09 15:02:38 -06:00
parent 208b618918
commit 3de93f556e
5 changed files with 28 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ class PostsController < ApplicationController
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])
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
@posts = authorize @post_set.posts, policy_class: PostPolicy
@post_set.log!
respond_with(@posts) do |format|
@@ -55,6 +56,7 @@ class PostsController < ApplicationController
def update
@post = authorize Post.find(params[:id])
@post.update(permitted_attributes(@post))
@preview_size = params[:size].presence || cookies[:post_preview_size].presence || PostPreviewComponent::DEFAULT_SIZE
respond_with_post_after_update(@post)
end