+
{ this.translate( 'Current Theme' ) }
@@ -70,4 +74,8 @@ var CurrentTheme = React.createClass( {
}
} );
-module.exports = CurrentTheme;
+export default connect(
+ ( state, props ) => (
+ { currentTheme: getCurrentTheme( state, props.site && props.site.ID ) }
+ )
+)( CurrentTheme );
diff --git a/client/my-sites/themes/single-site.jsx b/client/my-sites/themes/single-site.jsx
index e597ebc9818d09..404218af560750 100644
--- a/client/my-sites/themes/single-site.jsx
+++ b/client/my-sites/themes/single-site.jsx
@@ -11,7 +11,6 @@ var React = require( 'react' ),
* Internal dependencies
*/
var Main = require( 'components/main' ),
- CurrentThemeData = require( 'components/data/current-theme' ),
ActivatingTheme = require( 'components/data/activating-theme' ),
Action = require( 'state/themes/actions' ),
ThemePreview = require( './theme-preview' ),
@@ -153,11 +152,9 @@ var ThemesSingleSite = React.createClass( {
source={ 'list' }
clearActivated={ bindActionCreators( Action.clearActivated, this.props.dispatch ) } />
-
-
-
+
{
- wpcom.undocumented().activeTheme( site.ID )
+ dispatch( {
+ type: THEME_REQUEST_CURRENT,
+ siteId,
+ } );
+
+ wpcom.undocumented().activeTheme( siteId )
.then( theme => {
debug( 'Received current theme', theme );
dispatch( {
type: THEME_RECEIVE_CURRENT,
- site: site,
+ siteId,
themeId: theme.id,
themeName: theme.name,
themeCost: theme.cost
} );
- } ); // TODO: add .catch() error handler
+ } ).catch( error => {
+ dispatch( {
+ type: THEME_REQUEST_CURRENT_FAILURE,
+ siteId,
+ error,
+ } );
+ } );
};
}
diff --git a/client/state/themes/current-theme/reducer.js b/client/state/themes/current-theme/reducer.js
index 9019d2ffc380b6..75b44bfd0c38ab 100644
--- a/client/state/themes/current-theme/reducer.js
+++ b/client/state/themes/current-theme/reducer.js
@@ -13,30 +13,39 @@ import {
THEME_ACTIVATE,
THEME_ACTIVATED,
THEME_CLEAR_ACTIVATED,
- THEME_RECEIVE_CURRENT
+ THEME_RECEIVE_CURRENT,
+ THEME_REQUEST_CURRENT,
+ THEME_REQUEST_CURRENT_FAILURE,
} from 'state/action-types';
export const initialState = fromJS( {
isActivating: false,
hasActivated: false,
- currentThemes: {}
+ currentThemes: {},
+ requesting: {},
} );
export default ( state = initialState, action ) => {
switch ( action.type ) {
case THEME_RECEIVE_CURRENT:
- return state.setIn( [ 'currentThemes', action.site.ID ], {
+ return state.setIn( [ 'currentThemes', action.siteId ], {
name: action.themeName,
id: action.themeId,
- cost: action.themeCost
- } );
+ cost: action.themeCost,
+ } )
+ .setIn( [ 'requesting', action.siteId ], false );
+ case THEME_REQUEST_CURRENT:
+ return state.setIn( [ 'requesting', action.siteId ], true );
+ case THEME_REQUEST_CURRENT_FAILURE:
+ //TODO: show notification
+ return state.setIn( [ 'requesting', action.siteId ], false );
case THEME_ACTIVATE:
return state.set( 'isActivating', true );
case THEME_ACTIVATED:
return state
.set( 'isActivating', false )
.set( 'hasActivated', true )
- .setIn( [ 'currentThemes', action.site.ID ], action.theme );
+ .setIn( [ 'currentThemes', action.siteId ], action.theme );
case THEME_CLEAR_ACTIVATED:
return state.set( 'hasActivated', false );
case DESERIALIZE:
diff --git a/client/state/themes/current-theme/selectors.js b/client/state/themes/current-theme/selectors.js
index 7e9a0aeefc51da..b93f0c1c6829c3 100644
--- a/client/state/themes/current-theme/selectors.js
+++ b/client/state/themes/current-theme/selectors.js
@@ -11,3 +11,7 @@ export function isActivating( state ) {
export function hasActivated( state ) {
return state.themes.currentTheme.get( 'hasActivated' );
}
+
+export function isRequestingCurrentTheme( state, siteId ) {
+ return !! state.themes.currentTheme.get( 'requesting' ).get( siteId );
+}