posts: show length of videos and animations in thumbnails.
Show the length of videos and animated posts in the thumbnail. The length is shown the top left corner in MM:SS format. This replaces the play button icon. Show a speaker icon instead of a music note icon for posts with sound. Doing this requires doing `.includes(:media_asset)` in a bunch of places to avoid N+1 queries when we access the post's duration.
This commit is contained in:
@@ -5,7 +5,9 @@ class PostPreviewComponent < ApplicationComponent
|
||||
|
||||
attr_reader :post, :tags, :show_deleted, :show_cropped, :link_target, :pool, :similarity, :recommended, :compact, :size, :current_user, :options
|
||||
|
||||
delegate :external_link_to, :time_ago_in_words_tagged, :empty_heart_icon, to: :helpers
|
||||
delegate :external_link_to, :time_ago_in_words_tagged, :duration_to_hhmmss, :empty_heart_icon, :sound_icon, to: :helpers
|
||||
delegate :image_width, :image_height, :file_ext, :file_size, :duration, :is_animated?, to: :media_asset
|
||||
delegate :media_asset, to: :post
|
||||
|
||||
def initialize(post:, tags: "", show_deleted: false, show_cropped: true, link_target: post, pool: nil, similarity: nil, recommended: nil, compact: nil, size: nil, current_user: CurrentUser.user, **options)
|
||||
super
|
||||
@@ -67,7 +69,7 @@ class PostPreviewComponent < ApplicationComponent
|
||||
def data_attributes
|
||||
attributes = {
|
||||
"data-id" => post.id,
|
||||
"data-has-sound" => post.has_tag?("sound"),
|
||||
"data-has-sound" => has_sound?,
|
||||
"data-tags" => post.tag_string,
|
||||
"data-approver-id" => post.approver_id,
|
||||
"data-rating" => post.rating,
|
||||
@@ -96,4 +98,8 @@ class PostPreviewComponent < ApplicationComponent
|
||||
|
||||
attributes
|
||||
end
|
||||
|
||||
def has_sound?
|
||||
post.has_tag?("sound")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user