Skip to content

Commit 9b36f62

Browse files
NimaBoscarinoGargron
authored andcommitted
Add download button to audio and video players (mastodon#12179)
* Add download button for audio player * Add download button for video player * fix padding for download button in Audio component
1 parent 91945aa commit 9b36f62

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

app/javascript/mastodon/features/audio/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const messages = defineMessages({
1212
pause: { id: 'video.pause', defaultMessage: 'Pause' },
1313
mute: { id: 'video.mute', defaultMessage: 'Mute sound' },
1414
unmute: { id: 'video.unmute', defaultMessage: 'Unmute sound' },
15+
download: { id: 'video.download', defaultMessage: 'Download file' },
1516
});
1617

1718
export default @injectIntl
@@ -218,6 +219,14 @@ class Audio extends React.PureComponent {
218219
<span className='video-player__time-total'>{formatTime(this.state.duration || Math.floor(this.props.duration))}</span>
219220
</span>
220221
</div>
222+
223+
<div className='video-player__buttons right'>
224+
<button type='button' aria-label={intl.formatMessage(messages.download)}>
225+
<a className='video-player__download__icon' href={this.props.src} download>
226+
<Icon id={'download'} fixedWidth />
227+
</a>
228+
</button>
229+
</div>
221230
</div>
222231
</div>
223232
</div>

app/javascript/mastodon/features/video/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const messages = defineMessages({
1919
close: { id: 'video.close', defaultMessage: 'Close video' },
2020
fullscreen: { id: 'video.fullscreen', defaultMessage: 'Full screen' },
2121
exit_fullscreen: { id: 'video.exit_fullscreen', defaultMessage: 'Exit full screen' },
22+
download: { id: 'video.download', defaultMessage: 'Download file' },
2223
});
2324

2425
export const formatTime = secondsNum => {
@@ -494,7 +495,13 @@ class Video extends React.PureComponent {
494495
{(!onCloseVideo && !editable) && <button type='button' aria-label={intl.formatMessage(messages.hide)} onClick={this.toggleReveal}><Icon id='eye-slash' fixedWidth /></button>}
495496
{(!fullscreen && onOpenVideo) && <button type='button' aria-label={intl.formatMessage(messages.expand)} onClick={this.handleOpenVideo}><Icon id='expand' fixedWidth /></button>}
496497
{onCloseVideo && <button type='button' aria-label={intl.formatMessage(messages.close)} onClick={this.handleCloseVideo}><Icon id='compress' fixedWidth /></button>}
498+
<button type='button' aria-label={intl.formatMessage(messages.download)}>
499+
<a className='video-player__download__icon' href={this.props.src} download>
500+
<Icon id={'download'} fixedWidth />
501+
</a>
502+
</button>
497503
<button type='button' aria-label={intl.formatMessage(fullscreen ? messages.exit_fullscreen : messages.fullscreen)} onClick={this.toggleFullscreen}><Icon id={fullscreen ? 'compress' : 'arrows-alt'} fixedWidth /></button>
504+
498505
</div>
499506
</div>
500507
</div>

app/javascript/mastodon/locales/defaultMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,10 @@
776776
{
777777
"defaultMessage": "Unmute sound",
778778
"id": "video.unmute"
779+
},
780+
{
781+
"defaultMessage": "Download file",
782+
"id": "video.download"
779783
}
780784
],
781785
"path": "app/javascript/mastodon/features/audio/index.json"

app/javascript/styles/mastodon/components.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,10 @@ a.status-card.compact:hover {
53305330
display: flex;
53315331
justify-content: space-between;
53325332
padding-bottom: 10px;
5333+
5334+
.video-player__download__icon {
5335+
color: inherit;
5336+
}
53335337
}
53345338

53355339
&__buttons {

0 commit comments

Comments
 (0)