Skip to content

Commit

Permalink
Add download button to audio and video players (mastodon#12179)
Browse files Browse the repository at this point in the history
* Add download button for audio player

* Add download button for video player

* fix padding for download button in Audio component
  • Loading branch information
NimaBoscarino authored and Gargron committed Oct 25, 2019
1 parent 91945aa commit 9b36f62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/javascript/mastodon/features/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const messages = defineMessages({
pause: { id: 'video.pause', defaultMessage: 'Pause' },
mute: { id: 'video.mute', defaultMessage: 'Mute sound' },
unmute: { id: 'video.unmute', defaultMessage: 'Unmute sound' },
download: { id: 'video.download', defaultMessage: 'Download file' },
});

export default @injectIntl
Expand Down Expand Up @@ -218,6 +219,14 @@ class Audio extends React.PureComponent {
<span className='video-player__time-total'>{formatTime(this.state.duration || Math.floor(this.props.duration))}</span>
</span>
</div>

<div className='video-player__buttons right'>
<button type='button' aria-label={intl.formatMessage(messages.download)}>
<a className='video-player__download__icon' href={this.props.src} download>
<Icon id={'download'} fixedWidth />
</a>
</button>
</div>
</div>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions app/javascript/mastodon/features/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const messages = defineMessages({
close: { id: 'video.close', defaultMessage: 'Close video' },
fullscreen: { id: 'video.fullscreen', defaultMessage: 'Full screen' },
exit_fullscreen: { id: 'video.exit_fullscreen', defaultMessage: 'Exit full screen' },
download: { id: 'video.download', defaultMessage: 'Download file' },
});

export const formatTime = secondsNum => {
Expand Down Expand Up @@ -494,7 +495,13 @@ class Video extends React.PureComponent {
{(!onCloseVideo && !editable) && <button type='button' aria-label={intl.formatMessage(messages.hide)} onClick={this.toggleReveal}><Icon id='eye-slash' fixedWidth /></button>}
{(!fullscreen && onOpenVideo) && <button type='button' aria-label={intl.formatMessage(messages.expand)} onClick={this.handleOpenVideo}><Icon id='expand' fixedWidth /></button>}
{onCloseVideo && <button type='button' aria-label={intl.formatMessage(messages.close)} onClick={this.handleCloseVideo}><Icon id='compress' fixedWidth /></button>}
<button type='button' aria-label={intl.formatMessage(messages.download)}>
<a className='video-player__download__icon' href={this.props.src} download>
<Icon id={'download'} fixedWidth />
</a>
</button>
<button type='button' aria-label={intl.formatMessage(fullscreen ? messages.exit_fullscreen : messages.fullscreen)} onClick={this.toggleFullscreen}><Icon id={fullscreen ? 'compress' : 'arrows-alt'} fixedWidth /></button>

</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/mastodon/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@
{
"defaultMessage": "Unmute sound",
"id": "video.unmute"
},
{
"defaultMessage": "Download file",
"id": "video.download"
}
],
"path": "app/javascript/mastodon/features/audio/index.json"
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5330,6 +5330,10 @@ a.status-card.compact:hover {
display: flex;
justify-content: space-between;
padding-bottom: 10px;

.video-player__download__icon {
color: inherit;
}
}

&__buttons {
Expand Down

0 comments on commit 9b36f62

Please sign in to comment.