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).
This commit is contained in:
@@ -1,31 +1,27 @@
|
||||
# A component that displays a gallery of post thumbnails.
|
||||
#
|
||||
# There are three types of galleries:
|
||||
# There are two 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.
|
||||
# * 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 :posts, :current_user, :inline, :size, :options
|
||||
attr_reader :inline, :size, :options
|
||||
|
||||
delegate :post_preview, :numbered_paginator, to: :helpers
|
||||
# The list of posts in the gallery.
|
||||
renders_many :posts, PostPreviewComponent
|
||||
|
||||
# A gallery can optionally have a footer that displays between the posts and the paginator.
|
||||
# An optional footer that displays beneath the posts. Usually used for 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)
|
||||
# @param options [Hash] A set of options given to the PostPreviewComponent.
|
||||
def initialize(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
|
||||
|
||||
@@ -39,26 +35,8 @@ class PostGalleryComponent < ApplicationComponent
|
||||
def gallery_type
|
||||
if inline
|
||||
:inline
|
||||
elsif has_paginator?
|
||||
:paginated
|
||||
else
|
||||
:unpaginated
|
||||
:grid
|
||||
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
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
<div class="post-gallery post-gallery-<%= gallery_type %> post-gallery-<%= size %>">
|
||||
<% if empty? %>
|
||||
<% if posts.empty? %>
|
||||
<p>No posts found.</p>
|
||||
<% else %>
|
||||
<div class="posts-container grid gap-2">
|
||||
<% posts.each do |post| -%>
|
||||
<% %><%= post_preview(post, **options) -%>
|
||||
<% %><%= post -%>
|
||||
<% end -%>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= footer %>
|
||||
|
||||
<% if has_paginator? %>
|
||||
<%= numbered_paginator(posts) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
@import "../../javascript/src/styles/base/000_vars.scss";
|
||||
|
||||
article.post-preview {
|
||||
display: inline-block;
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
place-items: center;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -28,6 +30,7 @@ article.post-preview {
|
||||
.desc {
|
||||
font-size: var(--text-sm);
|
||||
margin-bottom: 0;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,22 @@ module ComponentsHelper
|
||||
render PostPreviewComponent.new(post: post, **options)
|
||||
end
|
||||
|
||||
def post_previews_html(posts, **options)
|
||||
# Render a set of posts as thumbnail gallery.
|
||||
#
|
||||
# @param posts [ActiveRecord::Relation<Post>, Array<Post>] A set of posts.
|
||||
# @param options [Hash] A hash of options for the PostGalleryComponent and PostPreviewComponent.
|
||||
def render_post_gallery(posts, **options, &block)
|
||||
posts = posts.includes(:media_asset) if posts.is_a?(ActiveRecord::Relation)
|
||||
render PostPreviewComponent.with_collection(posts, **options)
|
||||
end
|
||||
|
||||
def render_post_gallery(posts, current_user: CurrentUser.user, **options, &block)
|
||||
render PostGalleryComponent.new(posts: posts, current_user: current_user, **options), &block
|
||||
render(PostGalleryComponent.new(**options)) do |gallery|
|
||||
posts.each do |post|
|
||||
gallery.post(post: post, size: gallery.size, **options)
|
||||
end
|
||||
|
||||
if block_given?
|
||||
yield(gallery, posts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def render_comment(comment, current_user:, **options)
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
<%= render "explore/posts/nav_links", path: :curated_explore_posts_path, date: @date, scale: @scale %>
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= render_post_gallery(@posts) %>
|
||||
<%= render_post_gallery(@posts) do |gallery| %>
|
||||
<% gallery.footer do %>
|
||||
<%= numbered_paginator(@posts) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
<%= render "explore/posts/nav_links", path: :popular_explore_posts_path, date: @date, scale: @scale %>
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= render_post_gallery(@posts) %>
|
||||
<%= render_post_gallery(@posts) do |gallery| %>
|
||||
<% gallery.footer do %>
|
||||
<%= numbered_paginator(@posts) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= render_post_gallery(@posts, tags: "favgroup:#{@favorite_group.id}", show_deleted: true) %>
|
||||
<%= render_post_gallery(@posts, tags: "favgroup:#{@favorite_group.id}", show_deleted: true) do |gallery| %>
|
||||
<% gallery.footer do %>
|
||||
<%= numbered_paginator(@posts) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<section>
|
||||
<%= render(PostGalleryComponent.new) do |gallery| %>
|
||||
<% @pools.each do |pool| %>
|
||||
<%= post_preview(pool.cover_post, link_target: pool, pool: pool, show_deleted: true) %>
|
||||
<% gallery.post(post: pool.cover_post, link_target: pool, pool: pool, show_deleted: true) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@pools) %>
|
||||
</section>
|
||||
<%= numbered_paginator(@pools) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= render_post_gallery(@posts, tags: "pool:#{@pool.id}", show_deleted: @pool.is_series?) %>
|
||||
<%= render_post_gallery(@posts, tags: "pool:#{@pool.id}", show_deleted: @pool.is_series?) do |gallery| %>
|
||||
<% gallery.footer do %>
|
||||
<%= numbered_paginator(@posts) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<% if post_set.shown_posts.empty? %>
|
||||
<%= render "post_sets/blank" %>
|
||||
<% else %>
|
||||
<%= render_post_gallery(post_set.posts, show_deleted: post_set.show_deleted?, tags: post_set.tag_string, show_votes: post_set.show_votes?, size: params[:size]) do |gallery| %>
|
||||
<%= render_post_gallery(post_set.posts, show_deleted: post_set.show_deleted?, tags: post_set.tag_string, show_votes: post_set.show_votes?, size: params[:size]) do |gallery, posts| %>
|
||||
<% gallery.footer do %>
|
||||
<% if post_set.hidden_posts.present? %>
|
||||
<div class="fineprint hidden-posts-notice">
|
||||
@@ -32,6 +32,8 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(posts) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user