Skip to content

Commit

Permalink
Refactor actions
Browse files Browse the repository at this point in the history
  • Loading branch information
donnapep committed Jun 9, 2017
1 parent 93ac3a7 commit 4dbc3c3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 101 deletions.
33 changes: 11 additions & 22 deletions client/blocks/video-editor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ import ProgressBar from 'components/progress-bar';
import Notice from 'components/notice';
import DetailPreviewVideo from 'post-editor/media-modal/detail/detail-preview-video';
import VideoEditorButtons from './video-editor-buttons';
import {
resetState,
updatePoster,
} from 'state/ui/editor/video-editor/actions';
import { updatePoster } from 'state/ui/editor/video-editor/actions';
import {
getPosterUploadProgress,
getPosterUrl,
hasPosterUpdateError,
isPosterUpdated,
shouldCloseVideoEditorModal,
shouldShowVideoEditorError,
} from 'state/selectors';

/**
Expand All @@ -39,9 +36,9 @@ class VideoEditor extends Component {
onUpdatePoster: PropTypes.func,

// Connected props
hasPosterUpdateError: PropTypes.bool,
isPosterUpdated: PropTypes.bool,
posterUrl: PropTypes.string,
shouldCloseModal: PropTypes.bool,
shouldShowError: PropTypes.bool,
uploadProgress: PropTypes.number,
};

Expand All @@ -56,16 +53,12 @@ class VideoEditor extends Component {
pauseVideo: false,
};

componentDidMount() {
this.props.resetState();
}

componentWillReceiveProps( nextProps ) {
if ( ! nextProps.isPosterUpdated ) {
if ( ! nextProps.shouldCloseModal && ! nextProps.shouldShowError ) {
return;
}

if ( nextProps.hasPosterUpdateError ) {
if ( nextProps.shouldShowError ) {
this.setState( {
error: true,
pauseVideo: false
Expand All @@ -80,8 +73,6 @@ class VideoEditor extends Component {
handleSelectFrame = () => {
const { isLoading } = this.state;

this.props.resetState();

if ( isLoading ) {
this.setState( { error: true } );
return;
Expand Down Expand Up @@ -119,7 +110,6 @@ class VideoEditor extends Component {
handleUploadImageClick = () => {
isSelectingFrame = false;

this.props.resetState();
this.setState( {
error: false,
pauseVideo: true
Expand Down Expand Up @@ -201,7 +191,7 @@ class VideoEditor extends Component {
onVideoLoaded={ this.handleVideoLoaded }
/>
</div>
{ !! uploadProgress && ! error && ! isSelectingFrame &&
{ uploadProgress && ! error && ! isSelectingFrame &&
<ProgressBar
isPulsing={ true }
total={ 100 }
Expand All @@ -211,7 +201,7 @@ class VideoEditor extends Component {
{ translate( 'Select a frame to use as the thumbnail image or upload your own.' ) }
</span>
<VideoEditorButtons
isPosterUpdating={ !! uploadProgress && ! error }
isPosterUpdating={ uploadProgress && ! error }
isVideoLoading={ isLoading }
onCancel={ onCancel }
onSelectFrame={ this.handleSelectFrame }
Expand All @@ -228,14 +218,13 @@ class VideoEditor extends Component {
export default connect(
( state ) => {
return {
hasPosterUpdateError: hasPosterUpdateError( state ),
isPosterUpdated: isPosterUpdated( state ),
posterUrl: getPosterUrl( state ),
shouldCloseModal: shouldCloseVideoEditorModal( state ),
shouldShowError: shouldShowVideoEditorError( state ),
uploadProgress: getPosterUploadProgress( state ),
};
},
dispatch => bindActionCreators( {
resetState,
updatePoster,
}, dispatch ),
)( localize( VideoEditor ) );
10 changes: 0 additions & 10 deletions client/state/selectors/has-poster-update-error.js

This file was deleted.

8 changes: 0 additions & 8 deletions client/state/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,9 @@ export getUserSetting from './get-user-setting';
export getUserSettings from './get-user-settings';
export getVisibleSites from './get-visible-sites';
export hasBrokenSiteUserConnection from './has-broken-site-user-connection';
<<<<<<< HEAD
export hasInitializedSites from './has-initialized-sites';
export hasUnsavedUserSettings from './has-unsaved-user-settings';
export hasUserSettings from './has-user-settings';
=======
export hasPosterUpdateError from './has-poster-update-error';
>>>>>>> Move selectors and tests to state/selectors
export isAccountRecoveryResetOptionsReady from './is-account-recovery-reset-options-ready';
export isAccountRecoveryResetPasswordSucceeded from './is-account-recovery-reset-password-succeeded';
export isAccountRecoveryUserDataReady from './is-account-recovery-user-data-ready';
Expand Down Expand Up @@ -161,13 +157,9 @@ export isJetpackSettingsSaveFailure from './is-jetpack-settings-save-failure';
export isJetpackSiteInDevelopmentMode from './is-jetpack-site-in-development-mode';
export isJetpackSiteInStagingMode from './is-jetpack-site-in-staging-mode';
export isMappedDomainSite from './is-mapped-domain-site';
<<<<<<< HEAD
export isNotificationsOpen from './is-notifications-open';
export isPendingEmailChange from './is-pending-email-change';
export isPluginActive from './is-plugin-active';
=======
export isPosterUpdated from './is-poster-updated';
>>>>>>> Move selectors and tests to state/selectors
export isPrivateSite from './is-private-site';
export isPublicizeEnabled from './is-publicize-enabled';
export isReaderCardExpanded from './is-reader-card-expanded';
Expand Down
10 changes: 0 additions & 10 deletions client/state/selectors/is-poster-updated.js

This file was deleted.

25 changes: 0 additions & 25 deletions client/state/selectors/test/has-poster-update-error.js

This file was deleted.

25 changes: 0 additions & 25 deletions client/state/selectors/test/is-poster-updated.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/state/ui/editor/video-editor/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe( 'reducer', () => {
posterUrl,
} );

expect( state ).to.eql( url );
expect( state ).to.eql( posterUrl );
} );

it( 'should change to null on some other state change', () => {
Expand Down

0 comments on commit 4dbc3c3

Please sign in to comment.