Skip to content

Commit

Permalink
refactor download for items with captions/transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Jan 22, 2025
1 parent 0cc49f4 commit 08127a5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/companion_window.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@

ul {
list-style: none;
padding: 0px;

li {
margin-left: var(--drawer-content-padding);
margin-bottom: 1rem;
border-bottom: 1px solid lightgray;
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/embed/companion_windows_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
Files
</h3>
<ul>
<%= render Embed::Download::FileListItemComponent.with_collection(downloadable_files) %>
<%= render Embed::Download::FileListItemComponent.with_collection(downloadable_files, show_headers: show_headers?) %>
</ul>
<% else %>
<p>No downloads available</p>
Expand Down
7 changes: 7 additions & 0 deletions app/components/embed/companion_windows_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ def requested_by_chromium?

false
end

# We use this in the download FileListComponent to determine if we need to group files.
# For example, if a media file has a caption or transcript
# we will want to group the caption with the media file.
def show_headers?
downloadable_files.any? { |file| file.caption? || file.transcript? }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<% if show_headers && !file.caption? && !file.transcript? %>
<h4><%= download_label %></h4>
<% end %>
<li>
<a href='<%= url %>' target='_blank' rel='noopener noreferrer' download>
Download <%= download_label %>
Expand Down
5 changes: 3 additions & 2 deletions app/components/embed/download/file_list_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ module Embed
module Download
class FileListItemComponent < ViewComponent::Base
include Embed::PrettyFilesize
def initialize(file_list_item:, prefer_filename: false)
def initialize(file_list_item:, prefer_filename: false, show_headers: false)
@file = file_list_item
@prefer_filename = prefer_filename
@show_headers = show_headers
end
attr_reader :file
attr_reader :file, :show_headers

def file_size
"(#{pretty_filesize(file.size)})" if file.size
Expand Down

0 comments on commit 08127a5

Please sign in to comment.