Pushing for help with Redux selectors
This commit is contained in:
parent
ca527cc4c0
commit
bd3aa1b349
10 changed files with 98 additions and 3 deletions
|
@ -9,6 +9,7 @@ import { makeSelectCostInfoForUri } from "redux/selectors/cost_info";
|
||||||
import { doFetchAvailability } from "redux/actions/availability";
|
import { doFetchAvailability } from "redux/actions/availability";
|
||||||
import { doOpenFileInShell } from "redux/actions/file_info";
|
import { doOpenFileInShell } from "redux/actions/file_info";
|
||||||
import { doPurchaseUri, doStartDownload } from "redux/actions/content";
|
import { doPurchaseUri, doStartDownload } from "redux/actions/content";
|
||||||
|
import { setVideoPause } from "redux/actions/video";
|
||||||
import FileDownloadLink from "./view";
|
import FileDownloadLink from "./view";
|
||||||
|
|
||||||
const select = (state, props) => ({
|
const select = (state, props) => ({
|
||||||
|
@ -24,6 +25,7 @@ const perform = dispatch => ({
|
||||||
openInShell: path => dispatch(doOpenFileInShell(path)),
|
openInShell: path => dispatch(doOpenFileInShell(path)),
|
||||||
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
purchaseUri: uri => dispatch(doPurchaseUri(uri)),
|
||||||
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
|
||||||
|
videoPause: val => dispatch(setVideoPause(val)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(FileDownloadLink);
|
export default connect(select, perform)(FileDownloadLink);
|
||||||
|
|
|
@ -42,8 +42,15 @@ class FileDownloadLink extends React.PureComponent {
|
||||||
purchaseUri,
|
purchaseUri,
|
||||||
costInfo,
|
costInfo,
|
||||||
loading,
|
loading,
|
||||||
|
videoPause,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const openFile = () => {
|
||||||
|
openInShell(fileInfo.download_path);
|
||||||
|
console.log("FileDownloadLink view");
|
||||||
|
videoPause(true);
|
||||||
|
};
|
||||||
|
|
||||||
if (loading || downloading) {
|
if (loading || downloading) {
|
||||||
const progress =
|
const progress =
|
||||||
fileInfo && fileInfo.written_bytes
|
fileInfo && fileInfo.written_bytes
|
||||||
|
@ -93,7 +100,7 @@ class FileDownloadLink extends React.PureComponent {
|
||||||
button="text"
|
button="text"
|
||||||
icon="icon-external-link-square"
|
icon="icon-external-link-square"
|
||||||
className="no-underline"
|
className="no-underline"
|
||||||
onClick={() => openInShell(fileInfo.download_path)}
|
onClick={() => openFile()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
} from "redux/selectors/file_info";
|
} from "redux/selectors/file_info";
|
||||||
import { makeSelectCostInfoForUri } from "redux/selectors/cost_info";
|
import { makeSelectCostInfoForUri } from "redux/selectors/cost_info";
|
||||||
import { selectShowNsfw } from "redux/selectors/settings";
|
import { selectShowNsfw } from "redux/selectors/settings";
|
||||||
|
import { selectVideoPause } from "redux/selectors/video";
|
||||||
import Video from "./view";
|
import Video from "./view";
|
||||||
import { selectPlayingUri } from "redux/selectors/content";
|
import { selectPlayingUri } from "redux/selectors/content";
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ const select = (state, props) => ({
|
||||||
playingUri: selectPlayingUri(state),
|
playingUri: selectPlayingUri(state),
|
||||||
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
||||||
volume: selectVolume(state),
|
volume: selectVolume(state),
|
||||||
|
videoPause: selectVideoPause(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = dispatch => ({
|
const perform = dispatch => ({
|
||||||
|
|
|
@ -5,6 +5,9 @@ import player from "render-media";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import LoadingScreen from "./loading-screen";
|
import LoadingScreen from "./loading-screen";
|
||||||
|
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { selectVideoPause } from "redux/selectors/video";
|
||||||
|
|
||||||
class VideoPlayer extends React.PureComponent {
|
class VideoPlayer extends React.PureComponent {
|
||||||
static MP3_CONTENT_TYPES = ["audio/mpeg3", "audio/mpeg"];
|
static MP3_CONTENT_TYPES = ["audio/mpeg3", "audio/mpeg"];
|
||||||
|
|
||||||
|
@ -121,6 +124,11 @@ class VideoPlayer extends React.PureComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pauseVideo() {
|
||||||
|
console.log("pauseVideo called");
|
||||||
|
this.refs.media.children[0].pause();
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
const { contentType, downloadCompleted } = this.props;
|
const { contentType, downloadCompleted } = this.props;
|
||||||
const { startedPlaying } = this.state;
|
const { startedPlaying } = this.state;
|
||||||
|
@ -157,13 +165,15 @@ class VideoPlayer extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { mediaType, poster } = this.props;
|
const { mediaType, poster, videoPause } = this.props;
|
||||||
const { hasMetadata, unplayable } = this.state;
|
const { hasMetadata, unplayable } = this.state;
|
||||||
const noMetadataMessage = "Waiting for metadata.";
|
const noMetadataMessage = "Waiting for metadata.";
|
||||||
const unplayableMessage = "Sorry, looks like we can't play this file.";
|
const unplayableMessage = "Sorry, looks like we can't play this file.";
|
||||||
|
|
||||||
const needsMetadata = this.playableType();
|
const needsMetadata = this.playableType();
|
||||||
|
|
||||||
|
console.log("VideoPlayer render; videoPause:", videoPause);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{["audio", "application"].indexOf(mediaType) !== -1 &&
|
{["audio", "application"].indexOf(mediaType) !== -1 &&
|
||||||
|
|
|
@ -8,6 +8,7 @@ import NsfwOverlay from "component/nsfwOverlay";
|
||||||
class Video extends React.PureComponent {
|
class Video extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
console.log("PROPS:", props);
|
||||||
this.state = {
|
this.state = {
|
||||||
showNsfwHelp: false,
|
showNsfwHelp: false,
|
||||||
};
|
};
|
||||||
|
@ -56,8 +57,11 @@ class Video extends React.PureComponent {
|
||||||
changeVolume,
|
changeVolume,
|
||||||
volume,
|
volume,
|
||||||
uri,
|
uri,
|
||||||
|
videoPause,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
console.log("VIDEO VIEW videoPause:", videoPause);
|
||||||
|
|
||||||
const isPlaying = playingUri === uri;
|
const isPlaying = playingUri === uri;
|
||||||
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
||||||
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
|
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
|
||||||
|
@ -110,6 +114,7 @@ class Video extends React.PureComponent {
|
||||||
downloadCompleted={fileInfo.completed}
|
downloadCompleted={fileInfo.completed}
|
||||||
changeVolume={changeVolume}
|
changeVolume={changeVolume}
|
||||||
volume={volume}
|
volume={volume}
|
||||||
|
videoPause={videoPause}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{!isPlaying && (
|
{!isPlaying && (
|
||||||
|
|
|
@ -164,3 +164,8 @@ export const CLEAR_SHAPE_SHIFT = "CLEAR_SHAPE_SHIFT";
|
||||||
export const CHANNEL_SUBSCRIBE = "CHANNEL_SUBSCRIBE";
|
export const CHANNEL_SUBSCRIBE = "CHANNEL_SUBSCRIBE";
|
||||||
export const CHANNEL_UNSUBSCRIBE = "CHANNEL_UNSUBSCRIBE";
|
export const CHANNEL_UNSUBSCRIBE = "CHANNEL_UNSUBSCRIBE";
|
||||||
export const HAS_FETCHED_SUBSCRIPTIONS = "HAS_FETCHED_SUBSCRIPTIONS";
|
export const HAS_FETCHED_SUBSCRIPTIONS = "HAS_FETCHED_SUBSCRIPTIONS";
|
||||||
|
|
||||||
|
// Video controls
|
||||||
|
export const VIDEO_PAUSE_STARTED = "VIDEO_PAUSE_STARTED";
|
||||||
|
export const VIDEO_PAUSE_COMPLETED = "VIDEO_PAUSE_COMPLETED";
|
||||||
|
export const SET_VIDEO_PAUSE = "SET_VIDEO_PAUSE";
|
||||||
|
|
24
src/renderer/redux/actions/video.js
Normal file
24
src/renderer/redux/actions/video.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// @flow
|
||||||
|
import * as actions from "constants/action_types";
|
||||||
|
import type { Action, Dispatch } from "redux/reducers/video";
|
||||||
|
import lbry from "lbry";
|
||||||
|
|
||||||
|
// export const doVideoPause = (
|
||||||
|
// dispatch: Dispatch
|
||||||
|
// ) => {
|
||||||
|
// console.log("diVideoPause helllllo");
|
||||||
|
// console.log(dispatch);
|
||||||
|
// return dispatch({type: actions.VIDEO_PAUSE_STARTED});
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export const confirmVideoPause = (
|
||||||
|
// dispatch: Dispatch
|
||||||
|
// ) => dispatch({type: actions.VIDEO_PAUSE_COMPLETED});
|
||||||
|
|
||||||
|
export const setVideoPause = (data: boolean) => (dispatch: Dispatch) => {
|
||||||
|
console.log("VIDEO ACTION data:", data);
|
||||||
|
return dispatch({
|
||||||
|
type: actions.SET_VIDEO_PAUSE,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
};
|
29
src/renderer/redux/reducers/video.js
Normal file
29
src/renderer/redux/reducers/video.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// @flow
|
||||||
|
import * as actions from "constants/action_types";
|
||||||
|
import { handleActions } from "util/redux-utils";
|
||||||
|
|
||||||
|
export type VideoState = { videoPause: boolean };
|
||||||
|
|
||||||
|
type setVideoPause = {
|
||||||
|
type: actions.SET_VIDEO_PAUSE,
|
||||||
|
data: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Action = setVideoPause;
|
||||||
|
export type Dispatch = (action: Action) => any;
|
||||||
|
|
||||||
|
const defaultState = { videoPause: false };
|
||||||
|
|
||||||
|
export default handleActions(
|
||||||
|
{
|
||||||
|
[actions.SET_VIDEO_PAUSE]: (
|
||||||
|
state: VideoState,
|
||||||
|
action: setVideoPause
|
||||||
|
): VideoState => {
|
||||||
|
console.log("VIDEO REDUCER STATE", state);
|
||||||
|
console.log("VIDEO REDUCER ACTION", action);
|
||||||
|
return { ...state, videoPause: action.data };
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultState
|
||||||
|
);
|
9
src/renderer/redux/selectors/video.js
Normal file
9
src/renderer/redux/selectors/video.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import * as settings from "constants/settings";
|
||||||
|
import { createSelector } from "reselect";
|
||||||
|
|
||||||
|
const _selectState = state => state.videoPause || false;
|
||||||
|
|
||||||
|
export const selectVideoPause = createSelector(
|
||||||
|
_selectState,
|
||||||
|
state => state.videoPause || false
|
||||||
|
);
|
|
@ -13,6 +13,7 @@ import userReducer from "redux/reducers/user";
|
||||||
import walletReducer from "redux/reducers/wallet";
|
import walletReducer from "redux/reducers/wallet";
|
||||||
import shapeShiftReducer from "redux/reducers/shape_shift";
|
import shapeShiftReducer from "redux/reducers/shape_shift";
|
||||||
import subscriptionsReducer from "redux/reducers/subscriptions";
|
import subscriptionsReducer from "redux/reducers/subscriptions";
|
||||||
|
import videoReducer from "redux/reducers/video";
|
||||||
import { persistStore, autoRehydrate } from "redux-persist";
|
import { persistStore, autoRehydrate } from "redux-persist";
|
||||||
import createCompressor from "redux-persist-transform-compress";
|
import createCompressor from "redux-persist-transform-compress";
|
||||||
import createFilter from "redux-persist-transform-filter";
|
import createFilter from "redux-persist-transform-filter";
|
||||||
|
@ -20,7 +21,7 @@ import localForage from "localforage";
|
||||||
import { createStore, applyMiddleware, compose, combineReducers } from "redux";
|
import { createStore, applyMiddleware, compose, combineReducers } from "redux";
|
||||||
import thunk from "redux-thunk";
|
import thunk from "redux-thunk";
|
||||||
|
|
||||||
const env = process.env.NODE_ENV || "production"
|
const env = process.env.NODE_ENV || "production";
|
||||||
|
|
||||||
function isFunction(object) {
|
function isFunction(object) {
|
||||||
return typeof object === "function";
|
return typeof object === "function";
|
||||||
|
@ -69,6 +70,7 @@ const reducers = combineReducers({
|
||||||
user: userReducer,
|
user: userReducer,
|
||||||
shapeShift: shapeShiftReducer,
|
shapeShift: shapeShiftReducer,
|
||||||
subscriptions: subscriptionsReducer,
|
subscriptions: subscriptionsReducer,
|
||||||
|
video: videoReducer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const bulkThunk = createBulkThunkMiddleware();
|
const bulkThunk = createBulkThunkMiddleware();
|
||||||
|
|
Loading…
Reference in a new issue