Files
danbooru/app/components/post_gallery_component.rb
evazion 8841de68ac posts: add adjustable thumbnail sizes (#4932).
Add a menu in the top right of the post index page that lets you select
the thumbnail size.

This menu is currently hidden until the new thumbnails have been generated.

On desktop, there are five thumbnail sizes:

* Small:    150x150 (https://danbooru.donmai.us/posts?size=150)
* Medium:   180x180 (https://danbooru.donmai.us/posts?size=180)
* Large:    225x225 (https://danbooru.donmai.us/posts?size=225)
* Huge:     270x270 (https://danbooru.donmai.us/posts?size=270)
* Gigantic: 360x360 (https://danbooru.donmai.us/posts?size=360)

On mobile, there are four sizes:

* Small:  150x150 / 3 posts per row (https://danbooru.donmai.us/posts?size=150)
* Medium: 180x180 / 2 posts per row (https://danbooru.donmai.us/posts?size=180)
* Large:  225x225 / 2 posts per row (https://danbooru.donmai.us/posts?size=225)
* Huge:   360x360 / 1 posts per row (https://danbooru.donmai.us/posts?size=360)

There are two extra sizes that aren't listed in the menu:

* 225x360 (https://danbooru.donmai.us/posts?size=225w)
* 270x360 (https://danbooru.donmai.us/posts?size=270w)

These sizes are good for tall thumbnails, but not so much for wide
thumbnails. They aren't listed because in practice they're a bit too big.

The 225x225 and 270x270 sizes are really just 360x360 thumbnails scaled
down in HTML. This means 225x225 and 360x360 thumbnails both use the
same amount of bandwidth.

Thumbnail size is currently a per-search option, not a persistent
account-level setting.

This changes the HTML structure of thumbnails somewhat, so this may
break userscripts and custom CSS.
2021-12-04 06:30:29 -06:00

65 lines
1.9 KiB
Ruby

# A component that displays a gallery of post thumbnails.
#
# There are three types of galleries:
#
# * Paginated galleries, as seen on the post index page and pool show page.
# * Unpaginated galleries, as seen on wiki pages, artist pages, and user profiles.
# * Inline galleries that fit on a single row, as seen in parent/child post sets.
#
class PostGalleryComponent < ApplicationComponent
attr_reader :posts, :current_user, :inline, :size, :options
delegate :post_preview, :numbered_paginator, to: :helpers
# A gallery can optionally have a footer that displays between the posts and the paginator.
renders_one :footer
# @param posts [Array<Post>, ActiveRecord::Relation<Post>] The set of posts to display
# @param current_user [User] The current user.
# @param inline [Boolean] If true, the gallery is rendered as a single row with a
# horizontal scrollbar. If false, the gallery is rendered as a grid of thumbnails.
# @param size [String] The size of thumbnails in the gallery. Can be "150",
# "180", "225", "225w", "270", "270w", or "360".
# @param options [Hash] A set of options given to the thumbnail in `post_preview`.
def initialize(posts:, current_user:, inline: false, size: PostPreviewComponent::DEFAULT_SIZE, **options)
super
@posts = posts
@posts = @posts.includes(:media_asset) if posts.is_a?(ActiveRecord::Relation)
@current_user = current_user
@inline = inline
@options = options
if size.to_s.in?(PostPreviewComponent::SIZES)
@size = size
else
@size = PostPreviewComponent::DEFAULT_SIZE
end
end
def gallery_type
if inline
:inline
elsif has_paginator?
:paginated
else
:unpaginated
end
end
def has_paginator?
posts.respond_to?(:total_count)
end
def total_count
if has_paginator?
posts.total_count
else
posts.length
end
end
def empty?
total_count == 0
end
end