Add hotkey for opening media files (#12498)
* [WiP] Add hotkey to open media * Give focus to play/pause button when opening video modal
This commit is contained in:
		| @@ -214,6 +214,22 @@ class Status extends ImmutablePureComponent { | ||||
|     this.props.onOpenVideo(media, startTime); | ||||
|   } | ||||
|  | ||||
|   handleHotkeyOpenMedia = e => { | ||||
|     const { status, onOpenMedia, onOpenVideo } = this.props; | ||||
|  | ||||
|     e.preventDefault(); | ||||
|  | ||||
|     if (status.get('media_attachments').size > 0) { | ||||
|       if (status.getIn(['media_attachments', 0, 'type']) === 'audio') { | ||||
|         // TODO: toggle play/paused? | ||||
|       } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { | ||||
|         onOpenVideo(status.getIn(['media_attachments', 0]), 0); | ||||
|       } else { | ||||
|         onOpenMedia(status.get('media_attachments'), 0); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   handleHotkeyReply = e => { | ||||
|     e.preventDefault(); | ||||
|     this.props.onReply(this._properStatus(), this.context.router.history); | ||||
| @@ -293,6 +309,7 @@ class Status extends ImmutablePureComponent { | ||||
|       moveDown: this.handleHotkeyMoveDown, | ||||
|       toggleHidden: this.handleHotkeyToggleHidden, | ||||
|       toggleSensitive: this.handleHotkeyToggleSensitive, | ||||
|       openMedia: this.handleHotkeyOpenMedia, | ||||
|     }; | ||||
|  | ||||
|     if (hidden) { | ||||
|   | ||||
| @@ -56,6 +56,10 @@ class KeyboardShortcuts extends ImmutablePureComponent { | ||||
|                 <td><kbd>enter</kbd>, <kbd>o</kbd></td> | ||||
|                 <td><FormattedMessage id='keyboard_shortcuts.enter' defaultMessage='to open status' /></td> | ||||
|               </tr> | ||||
|               <tr> | ||||
|                 <td><kbd>e</kbd></td> | ||||
|                 <td><FormattedMessage id='keyboard_shortcuts.open_media' defaultMessage='to open media' /></td> | ||||
|               </tr> | ||||
|               <tr> | ||||
|                 <td><kbd>x</kbd></td> | ||||
|                 <td><FormattedMessage id='keyboard_shortcuts.toggle_hidden' defaultMessage='to show/hide text behind CW' /></td> | ||||
|   | ||||
| @@ -281,6 +281,22 @@ class Status extends ImmutablePureComponent { | ||||
|     this.props.dispatch(openModal('VIDEO', { media, time })); | ||||
|   } | ||||
|  | ||||
|   handleHotkeyOpenMedia = e => { | ||||
|     const { status } = this.props; | ||||
|  | ||||
|     e.preventDefault(); | ||||
|  | ||||
|     if (status.get('media_attachments').size > 0) { | ||||
|       if (status.getIn(['media_attachments', 0, 'type']) === 'audio') { | ||||
|         // TODO: toggle play/paused? | ||||
|       } else if (status.getIn(['media_attachments', 0, 'type']) === 'video') { | ||||
|         this.handleOpenVideo(status.getIn(['media_attachments', 0]), 0); | ||||
|       } else { | ||||
|         this.handleOpenMedia(status.get('media_attachments'), 0); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   handleMuteClick = (account) => { | ||||
|     this.props.dispatch(initMuteModal(account)); | ||||
|   } | ||||
| @@ -506,6 +522,7 @@ class Status extends ImmutablePureComponent { | ||||
|       openProfile: this.handleHotkeyOpenProfile, | ||||
|       toggleHidden: this.handleHotkeyToggleHidden, | ||||
|       toggleSensitive: this.handleHotkeyToggleSensitive, | ||||
|       openMedia: this.handleHotkeyOpenMedia, | ||||
|     }; | ||||
|  | ||||
|     return ( | ||||
|   | ||||
| @@ -100,6 +100,7 @@ const keyMap = { | ||||
|   goToRequests: 'g r', | ||||
|   toggleHidden: 'x', | ||||
|   toggleSensitive: 'h', | ||||
|   openMedia: 'e', | ||||
| }; | ||||
|  | ||||
| class SwitchingColumnsArea extends React.PureComponent { | ||||
|   | ||||
| @@ -467,7 +467,7 @@ class Video extends React.PureComponent { | ||||
|  | ||||
|           <div className='video-player__buttons-bar'> | ||||
|             <div className='video-player__buttons left'> | ||||
|               <button type='button' aria-label={intl.formatMessage(paused ? messages.play : messages.pause)} onClick={this.togglePlay}><Icon id={paused ? 'play' : 'pause'} fixedWidth /></button> | ||||
|               <button type='button' aria-label={intl.formatMessage(paused ? messages.play : messages.pause)} onClick={this.togglePlay} autoFocus={detailed}><Icon id={paused ? 'play' : 'pause'} fixedWidth /></button> | ||||
|               <button type='button' aria-label={intl.formatMessage(muted ? messages.unmute : messages.mute)} onClick={this.toggleMute}><Icon id={muted ? 'volume-off' : 'volume-up'} fixedWidth /></button> | ||||
|  | ||||
|               <div className='video-player__volume' onMouseDown={this.handleVolumeMouseDown} ref={this.setVolumeRef}> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user