Enable viewer shortcut keys #2604

Merged
btzr-io merged 1 commit from fullscreen-fix into master 2019-07-05 17:12:04 +02:00
5 changed files with 33 additions and 25 deletions

View file

@ -11,7 +11,6 @@ import {
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
makeSelectLoadingForUri, makeSelectLoadingForUri,
makeSelectDownloadingForUri, makeSelectDownloadingForUri,
selectSearchBarFocused,
makeSelectFirstRecommendedFileForUri, makeSelectFirstRecommendedFileForUri,
makeSelectClaimIsNsfw, makeSelectClaimIsNsfw,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
@ -34,7 +33,6 @@ const select = (state, props) => ({
volume: selectVolume(state), volume: selectVolume(state),
position: makeSelectContentPositionForUri(props.uri)(state), position: makeSelectContentPositionForUri(props.uri)(state),
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state), autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
searchBarFocused: selectSearchBarFocused(state),
fileInfoErrors: selectFileInfoErrors(state), fileInfoErrors: selectFileInfoErrors(state),
nextFileToPlay: makeSelectFirstRecommendedFileForUri(props.uri)(state), nextFileToPlay: makeSelectFirstRecommendedFileForUri(props.uri)(state),
nsfw: makeSelectClaimIsNsfw(props.uri)(state), nsfw: makeSelectClaimIsNsfw(props.uri)(state),

View file

@ -12,6 +12,7 @@ import path from 'path';
import player from 'render-media'; import player from 'render-media';
import FileRender from 'component/fileRender'; import FileRender from 'component/fileRender';
import LoadingScreen from 'component/common/loading-screen'; import LoadingScreen from 'component/common/loading-screen';
import detectTyping from 'util/detect-typing';
import { fullscreenElement, requestFullscreen, exitFullscreen } from 'util/full-screen'; import { fullscreenElement, requestFullscreen, exitFullscreen } from 'util/full-screen';
// Shorcut key code for fullscreen (f) // Shorcut key code for fullscreen (f)
@ -31,7 +32,6 @@ type Props = {
savePosition: number => void, savePosition: number => void,
changeVolume: number => void, changeVolume: number => void,
viewerContainer: { current: ElementRef<any> }, viewerContainer: { current: ElementRef<any> },
searchBarFocused: boolean,
}; };
type State = { type State = {
@ -96,6 +96,9 @@ class MediaPlayer extends React.PureComponent<Props, State> {
} }
}, 5000); }, 5000);
// @endif // @endif
// Register handler for custom shortcut keys
document.addEventListener('keydown', this.handleKeyDown);
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
@ -115,27 +118,23 @@ class MediaPlayer extends React.PureComponent<Props, State> {
componentWillUnmount() { componentWillUnmount() {
const mediaElement = this.mediaContainer.current.children[0]; const mediaElement = this.mediaContainer.current.children[0];
// Temorarily removing for comments the keydown handler needs to know
// if a user is typing
// document.removeEventListener('keydown', this.handleKeyDown);
if (mediaElement) { if (mediaElement) {
mediaElement.removeEventListener('click', this.togglePlay); mediaElement.removeEventListener('click', this.togglePlay);
mediaElement.removeEventListener('dbclick', this.handleDoubleClick); mediaElement.removeEventListener('dbclick', this.handleDoubleClick);
} }
document.removeEventListener('keydown', this.handleKeyDown);
} }
handleKeyDown = (event: SyntheticKeyboardEvent<*>) => { handleKeyDown = (event: KeyboardEvent) => {
const { searchBarFocused } = this.props; if (!detectTyping()) {
if (!searchBarFocused) {
// Handle fullscreen shortcut key (f) // Handle fullscreen shortcut key (f)
if (event.keyCode === F_KEYCODE) { if (event.keyCode === F_KEYCODE) {
// this.toggleFullscreen(); this.toggleFullscreen();
} }
// Handle toggle play // Handle toggle play
// @if TARGET='app' // @if TARGET='app'
// this.togglePlay(event); this.togglePlay(event);
// @endif // @endif
} }
}; };

View file

@ -6,6 +6,7 @@ import classnames from 'classnames';
import analytics from 'analytics'; import analytics from 'analytics';
import LoadingScreen from 'component/common/loading-screen'; import LoadingScreen from 'component/common/loading-screen';
import PlayButton from './internal/play-button'; import PlayButton from './internal/play-button';
import detectTyping from 'util/detect-typing';
const Player = React.lazy(() => const Player = React.lazy(() =>
import( import(
@ -43,7 +44,6 @@ type Props = {
className: ?string, className: ?string,
obscureNsfw: boolean, obscureNsfw: boolean,
play: string => void, play: string => void,
searchBarFocused: boolean,
mediaType: string, mediaType: string,
claimRewards: () => void, claimRewards: () => void,
nextFileToPlay: ?string, nextFileToPlay: ?string,
@ -77,9 +77,7 @@ class FileViewer extends React.PureComponent<Props> {
} }
this.handleAutoplay(this.props); this.handleAutoplay(this.props);
// Commented out because it would play/pause if you were typing in the comment field window.addEventListener('keydown', this.handleKeyDown);
// Need a way to check if you are typing
// window.addEventListener('keydown', this.handleKeyDown);
} }
componentDidUpdate(prev: Props) { componentDidUpdate(prev: Props) {
@ -127,13 +125,11 @@ class FileViewer extends React.PureComponent<Props> {
} }
this.props.cancelPlay(); this.props.cancelPlay();
// window.removeEventListener('keydown', this.handleKeyDown); window.removeEventListener('keydown', this.handleKeyDown);
} }
handleKeyDown(event: SyntheticKeyboardEvent<*>) { handleKeyDown(event: KeyboardEvent) {
const { searchBarFocused } = this.props; if (!detectTyping()) {
if (!searchBarFocused) {
if (event.keyCode === SPACE_BAR_KEYCODE) { if (event.keyCode === SPACE_BAR_KEYCODE) {
event.preventDefault(); // prevent page scroll event.preventDefault(); // prevent page scroll
this.playContent(); this.playContent();
@ -233,7 +229,6 @@ class FileViewer extends React.PureComponent<Props> {
mediaType, mediaType,
insufficientCredits, insufficientCredits,
viewerContainer, viewerContainer,
searchBarFocused,
thumbnail, thumbnail,
nsfw, nsfw,
} = this.props; } = this.props;
@ -294,7 +289,6 @@ class FileViewer extends React.PureComponent<Props> {
onStartCb={this.onFileStartCb} onStartCb={this.onFileStartCb}
onFinishCb={this.onFileFinishCb} onFinishCb={this.onFileFinishCb}
playingUri={playingUri} playingUri={playingUri}
searchBarFocused={searchBarFocused}
viewerContainer={viewerContainer} viewerContainer={viewerContainer}
/> />
</Suspense> </Suspense>

View file

@ -0,0 +1,13 @@
// A simple function to detect if a user is typing:
// useful when hanlding shorcut keys.
export default function detectTyping() {
const activeElement = document.activeElement;
neb-b commented 2019-07-05 17:11:52 +02:00 (Migrated from github.com)
Review

TIL. Nice!

TIL. Nice!
if (activeElement) {
const elementType = activeElement.tagName.toLowerCase();
return elementType === 'input' || elementType === 'textarea';
}
return false;
}

View file

@ -479,5 +479,9 @@
"We know this page won't win any design awards, we have a cool idea for channel edits in the future. We just wanted to release a very very very basic version that just barely kinda works so people can use": "We know this page won't win any design awards, we have a cool idea for channel edits in the future. We just wanted to release a very very very basic version that just barely kinda works so people can use", "We know this page won't win any design awards, we have a cool idea for channel edits in the future. We just wanted to release a very very very basic version that just barely kinda works so people can use": "We know this page won't win any design awards, we have a cool idea for channel edits in the future. We just wanted to release a very very very basic version that just barely kinda works so people can use",
"We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use", "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use",
"We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version in the works.": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version in the works.", "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version in the works.": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version in the works.",
"We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version being worked on.": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version being worked on." "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version being worked on.": "We know this page won't win any design awards, we just wanted to release a very very very basic version that just barely kinda works so people can use it right now. There is a much nicer version being worked on.",
"Got it!": "Got it!",
btzr-io commented 2019-07-04 06:43:08 +02:00 (Migrated from github.com)
Review

not sure what happen here, I didn't touch this file 😕

not sure what happen here, I didn't touch this file :confused:
btzr-io commented 2019-07-04 22:34:32 +02:00 (Migrated from github.com)
Review

I guess this is an automated task ?

I guess this is an automated task ?
"Filter": "Filter",
"Rendering document.": "Rendering document.",
"Sorry, looks like we can't load the document.": "Sorry, looks like we can't load the document."
} }