diff --git a/client/my-sites/themes/helpers.js b/client/my-sites/themes/helpers.js index a4a416568d0e8f..5faaed2cf09331 100644 --- a/client/my-sites/themes/helpers.js +++ b/client/my-sites/themes/helpers.js @@ -9,17 +9,6 @@ import mapValues from 'lodash/mapValues'; * Internal dependencies */ import { sectionify } from 'lib/route/path'; -import { oldShowcaseUrl } from 'state/themes/utils'; - -export function getExternalThemesUrl( site ) { - if ( ! site ) { - return oldShowcaseUrl; - } - if ( site.jetpack ) { - return site.options.admin_url + 'theme-install.php'; - } - return oldShowcaseUrl + site.slug; -} export function trackClick( componentName, eventName, verb = 'click' ) { const stat = `${ componentName } ${ eventName } ${ verb }`; diff --git a/client/my-sites/themes/theme-showcase.jsx b/client/my-sites/themes/theme-showcase.jsx index 43ea43b86ed3ef..fc5a541054b391 100644 --- a/client/my-sites/themes/theme-showcase.jsx +++ b/client/my-sites/themes/theme-showcase.jsx @@ -132,7 +132,6 @@ const ThemeShowcase = React.createClass( { render() { const { - site, siteId, options, getScreenshotOption, @@ -156,7 +155,6 @@ const ThemeShowcase = React.createClass( { ( { + isJetpack: isJetpackSite( state, getSelectedSiteId( state ) ) + } ) +)( localize( ThemesMagicSearchCard ) ); diff --git a/client/my-sites/themes/themes-search-card/index.jsx b/client/my-sites/themes/themes-search-card/index.jsx index 58f0e11b531e19..1a1e7c9cb1c99f 100644 --- a/client/my-sites/themes/themes-search-card/index.jsx +++ b/client/my-sites/themes/themes-search-card/index.jsx @@ -2,6 +2,7 @@ * External dependencies */ import React from 'react'; +import { connect } from 'react-redux'; import find from 'lodash/find'; import debounce from 'lodash/debounce'; import { localize } from 'i18n-calypso'; @@ -14,17 +15,22 @@ import ThemesSelectDropdown from './select-dropdown'; import SectionNav from 'components/section-nav'; import NavTabs from 'components/section-nav/tabs'; import NavItem from 'components/section-nav/item'; -import { getExternalThemesUrl, trackClick } from '../helpers'; +import { trackClick } from '../helpers'; import config from 'config'; import { isMobile } from 'lib/viewport'; +import { getSiteAdminUrl, getSiteSlug, isJetpackSite } from 'state/sites/selectors'; +import { oldShowcaseUrl } from 'state/themes/utils'; +import { getSelectedSiteId } from 'state/ui/selectors'; const ThemesSearchCard = React.createClass( { propTypes: { tier: React.PropTypes.string, select: React.PropTypes.func.isRequired, - site: React.PropTypes.object, + siteId: React.PropTypes.number, onSearch: React.PropTypes.func.isRequired, - search: React.PropTypes.string + search: React.PropTypes.string, + externalUrl: React.PropTypes.string, + isJetpack: React.PropTypes.bool }, trackClick: trackClick.bind( null, 'search bar' ), @@ -71,7 +77,7 @@ const ThemesSearchCard = React.createClass( { }, renderMobile( tiers ) { - const isJetpack = this.props.site && this.props.site.jetpack; + const { isJetpack } = this.props; const isPremiumThemesEnabled = config.isEnabled( 'upgrades/premium-themes' ); const selectedTiers = isPremiumThemesEnabled ? tiers : [ find( tiers, tier => tier.value === 'free' ) ]; @@ -85,7 +91,7 @@ const ThemesSearchCard = React.createClass( { { isPremiumThemesEnabled &&
} { isPremiumThemesEnabled && { this.props.translate( 'More' ) + ' ' } @@ -111,7 +117,7 @@ const ThemesSearchCard = React.createClass( { }, render() { - const isJetpack = this.props.site && this.props.site.jetpack; + const { isJetpack } = this.props; const isPremiumThemesEnabled = config.isEnabled( 'upgrades/premium-themes' ); const tiers = [ @@ -142,7 +148,7 @@ const ThemesSearchCard = React.createClass( { onSelect={ this.props.select } /> } { config.isEnabled( 'manage/themes/upload' ) && ! isJetpack && @@ -154,4 +160,20 @@ const ThemesSearchCard = React.createClass( { } } ); -export default localize( ThemesSearchCard ); +export default connect( + ( state ) => { + const siteId = getSelectedSiteId( state ); + const isJetpack = isJetpackSite( state, siteId ); + + let externalUrl; + if ( ! siteId ) { + externalUrl = oldShowcaseUrl; + } else if ( isJetpack ) { + externalUrl = getSiteAdminUrl( state, siteId, 'theme-install.php' ); + } else { + externalUrl = oldShowcaseUrl + getSiteSlug( state, siteId ); + } + + return { externalUrl, isJetpack }; + } +)( localize( ThemesSearchCard ) );