Skip to content

Commit

Permalink
Importer: Continue reduxification work (#5936)
Browse files Browse the repository at this point in the history
Updates the `startImport` action, which is one of the few actions that
can be simply converted without getting into thunk issues.
  • Loading branch information
dmsnell authored Jun 15, 2016
1 parent d1fb60a commit dc37d5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 4 additions & 4 deletions client/lib/importer/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ export function setUploadProgress( importerId, data ) {
} );
}

export function startImport( siteId, importerType ) {
export const startImport = ( siteId, importerType ) => {
// Use a fake ID until the server returns the real one
let importerId = `${ ID_GENERATOR_PREFIX }${ Math.round( Math.random() * 10000 ) }`;

Dispatcher.handleViewAction( {
return {
type: IMPORTS_IMPORT_START,
importerId,
importerType,
siteId
} );
}
};
};

export function startImporting( importerStatus ) {
const { importerId, site: { ID: siteId } } = importerStatus;
Expand Down
22 changes: 20 additions & 2 deletions client/my-sites/importer/importer-header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Button from 'components/forms/form-button';
import { appStates } from 'state/imports/constants';
import { cancelImport, resetImport, startImport } from 'lib/importer/actions';
import SocialLogo from 'components/social-logo';
import flowRight from 'lodash/flowRight';
import { connectDispatcher } from './dispatcher-converter';

/**
* Module variables
Expand All @@ -27,7 +29,7 @@ const startStates = [ appStates.DISABLED, appStates.INACTIVE ],
stopStates = [ appStates.IMPORT_FAILURE, appStates.IMPORTING ],
doneStates = [ appStates.IMPORT_SUCCESS ];

export default React.createClass( {
export const ImporterHeader = React.createClass( {
displayName: 'ImporterHeader',

mixins: [ PureRenderMixin ],
Expand All @@ -44,7 +46,17 @@ export default React.createClass( {
},

controlButtonClicked: function() {
const { importerStatus: { importerId, importerState, type }, site: { ID: siteId } } = this.props;
const {
importerStatus: {
importerId,
importerState,
type
},
site: {
ID: siteId
},
startImport
} = this.props;

if ( includes( [ ...cancelStates, ...stopStates ], importerState ) ) {
cancelImport( siteId, importerId );
Expand Down Expand Up @@ -102,3 +114,9 @@ export default React.createClass( {
);
}
} );

const mapDispatchToProps = dispatch => ( {
startImport: flowRight( dispatch, startImport )
} );

export default connectDispatcher( null, mapDispatchToProps )( ImporterHeader );

0 comments on commit dc37d5c

Please sign in to comment.