Skip to content

Commit 54ca242

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Add attachment list fallback to public pages (mastodon#9780)
* Add attachment list fallback to public pages Fixes mastodon#6714 * Refactor attachments lists
1 parent 055577a commit 54ca242

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ def opengraph(property, content)
6969
tag(:meta, content: content, property: property)
7070
end
7171

72-
def react_component(name, props = {})
73-
content_tag(:div, nil, data: { component: name.to_s.camelcase, props: Oj.dump(props) })
72+
def react_component(name, props = {}, &block)
73+
if block.nil?
74+
content_tag(:div, nil, data: { component: name.to_s.camelcase, props: Oj.dump(props) })
75+
else
76+
content_tag(:div, data: { component: name.to_s.camelcase, props: Oj.dump(props) }, &block)
77+
end
7478
end
7579

7680
def body_classes

app/javascript/packs/public.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ function main() {
8383
if (reactComponents.length > 0) {
8484
import(/* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container')
8585
.then(({ default: MediaContainer }) => {
86+
[].forEach.call(reactComponents, (component) => {
87+
[].forEach.call(component.children, (child) => {
88+
component.removeChild(child);
89+
});
90+
});
91+
8692
const content = document.createElement('div');
8793

8894
ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.attachment-list
2+
.attachment-list__icon
3+
= fa_icon 'link'
4+
%ul.attachment-list__list
5+
- attachments.each do |media|
6+
%li
7+
- url = media.remote_url.presence || media.file.url
8+
= link_to File.basename(url), url, title: media.description

app/views/stream_entries/_detailed_status.html.haml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
- if !status.media_attachments.empty?
2626
- if status.media_attachments.first.video?
2727
- video = status.media_attachments.first
28-
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 670, height: 380, detailed: true, inline: true, alt: video.description
28+
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 670, height: 380, detailed: true, inline: true, alt: video.description do
29+
= render partial: 'stream_entries/attachment_list', locals: { attachments: status.media_attachments }
2930
- else
30-
= react_component :media_gallery, height: 380, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, standalone: true, 'autoPlayGif': current_account&.user&.setting_auto_play_gif || autoplay, 'reduceMotion': current_account&.user&.setting_reduce_motion, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }
31+
= react_component :media_gallery, height: 380, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, standalone: true, 'autoPlayGif': current_account&.user&.setting_auto_play_gif || autoplay, 'reduceMotion': current_account&.user&.setting_reduce_motion, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json } do
32+
= render partial: 'stream_entries/attachment_list', locals: { attachments: status.media_attachments }
3133
- elsif status.preview_card
3234
= react_component :card, 'maxDescription': 160, card: ActiveModelSerializers::SerializableResource.new(status.preview_card, serializer: REST::PreviewCardSerializer).as_json
3335

app/views/stream_entries/_simple_status.html.haml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
- if !status.media_attachments.empty?
3030
- if status.media_attachments.first.video?
3131
- video = status.media_attachments.first
32-
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 610, height: 343, inline: true, alt: video.description
32+
= react_component :video, src: video.file.url(:original), preview: video.file.url(:small), sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, width: 610, height: 343, inline: true, alt: video.description do
33+
= render partial: 'stream_entries/attachment_list', locals: { attachments: status.media_attachments }
3334
- else
34-
= react_component :media_gallery, height: 343, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, 'autoPlayGif': current_account&.user&.setting_auto_play_gif || autoplay, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json }
35+
= react_component :media_gallery, height: 343, sensitive: !current_account&.user&.show_all_media? && status.sensitive? || current_account&.user&.hide_all_media?, 'autoPlayGif': current_account&.user&.setting_auto_play_gif || autoplay, media: status.media_attachments.map { |a| ActiveModelSerializers::SerializableResource.new(a, serializer: REST::MediaAttachmentSerializer).as_json } do
36+
= render partial: 'stream_entries/attachment_list', locals: { attachments: status.media_attachments }
3537
- elsif status.preview_card
3638
= react_component :card, 'maxDescription': 160, card: ActiveModelSerializers::SerializableResource.new(status.preview_card, serializer: REST::PreviewCardSerializer).as_json
3739

0 commit comments

Comments
 (0)