Files
danbooru/app/components/post_gallery_component.rb
evazion 2e6f480d07 pools: fix pool gallery page layout.
Fix the /pools/gallery page layout being broken by 8841de68a.

This required refactoring the PostGalleryComponent to take a set of
PostPreviewComponents instead of a set of Posts.

The upshot is that it's technically possible to have adjustable
thumbnail sizes on the pool gallery page now (although this is not yet
exposed in the UI).
2021-12-05 02:52:07 -06:00

43 lines
1.3 KiB
Ruby

# A component that displays a gallery of post thumbnails.
#
# There are two types of galleries:
#
# * Grid galleries, where posts are arranged in a fixed grid.
# * Inline galleries, where posts are arranged on a single scrollable row, as
# seen in parent/child post sets.
#
class PostGalleryComponent < ApplicationComponent
attr_reader :inline, :size, :options
# The list of posts in the gallery.
renders_many :posts, PostPreviewComponent
# An optional footer that displays beneath the posts. Usually used for the paginator.
renders_one :footer
# @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 PostPreviewComponent.
def initialize(inline: false, size: PostPreviewComponent::DEFAULT_SIZE, **options)
super
@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
else
:grid
end
end
end