best 7 lines ever

This commit is contained in:
Jeremy Kauffman 2020-03-19 16:25:37 -04:00 committed by Jeremy Kauffman
parent 169ae49b06
commit ef4d8f5988
2 changed files with 12 additions and 8 deletions

View file

@ -3,7 +3,6 @@ import { makeSelectClaimForUri, makeSelectFileInfoForUri, makeSelectThumbnailFor
import { doChangeVolume, doChangeMute } from 'redux/actions/app';
import { selectVolume, selectMute } from 'redux/selectors/app';
import { savePosition, doSetPlayingUri } from 'redux/actions/content';
import { makeSelectContentPositionForUri } from 'redux/selectors/content';
import VideoViewer from './view';
import { withRouter } from 'react-router';
@ -11,11 +10,13 @@ const select = (state, props) => {
const { search } = props.location;
const urlParams = new URLSearchParams(search);
const autoplay = urlParams.get('autoplay');
const position = urlParams.get('t');
return {
autoplayParam: autoplay,
volume: selectVolume(state),
position: makeSelectContentPositionForUri(props.uri)(state),
muted: selectMute(state),
position: position,
hasFileInfo: Boolean(makeSelectFileInfoForUri(props.uri)(state)),
thumbnail: makeSelectThumbnailForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri)(state),
@ -29,9 +30,4 @@ const perform = dispatch => ({
setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
});
export default withRouter(
connect(
select,
perform
)(VideoViewer)
);
export default withRouter(connect(select, perform)(VideoViewer));

View file

@ -67,6 +67,7 @@ function VideoViewer(props: Props) {
volume,
muted,
thumbnail,
position,
claim,
autoplayParam,
} = props;
@ -74,6 +75,7 @@ function VideoViewer(props: Props) {
const videoRef = useRef();
const isAudio = contentType.includes('audio');
const embedded = useContext(EmbedContext);
if (embedded && !autoplayParam) {
VIDEO_JS_OPTIONS.autoplay = false;
}
@ -249,6 +251,12 @@ function VideoViewer(props: Props) {
};
}, [player]);
useEffect(() => {
if (player && position) {
player.currentTime(position);
}
}, [player, position]);
return (
<div className="file-render__viewer" onContextMenu={stopContextMenu}>
{!requireRedraw && (