Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update <Site> component to use ES6 syntax. #3338

Merged
merged 2 commits into from
Mar 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 82 additions & 71 deletions client/my-sites/site/index.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
/**
* External dependencies
*/
var React = require( 'react' ),
classNames = require( 'classnames' ),
noop = require( 'lodash/noop' );
import React from 'react';
import classnames from 'classnames';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you avoiding camelCase on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary here.

import noop from 'lodash/noop';

/**
* Internal dependencies
*/
var SiteIcon = require( 'components/site-icon' ),
Gridicon = require( 'components/gridicon' ),
SiteIndicator = require( 'my-sites/site-indicator' ),
getCustomizeUrl = require( 'my-sites/themes/helpers' ).getCustomizeUrl,
sites = require( 'lib/sites-list' )();

import SiteIcon from 'components/site-icon';
import Gridicon from 'components/gridicon';
import SiteIndicator from 'my-sites/site-indicator';
import { getCustomizeUrl } from 'my-sites/themes/helpers';
import sitesList from 'lib/sites-list';
import { userCan } from 'lib/site/utils';
import Tooltip from 'components/tooltip';
import ExternalLink from 'components/external-link';

module.exports = React.createClass( {
const sites = sitesList();

export default React.createClass( {
displayName: 'Site',

getDefaultProps: function() {
getDefaultProps() {
return {
// onSelect callback
onSelect: noop,
Expand Down Expand Up @@ -59,14 +60,14 @@ module.exports = React.createClass( {
disableStarring: React.PropTypes.bool
},

getInitialState: function() {
getInitialState() {
return {
showActions: false,
starTooltip: false
};
},

onSelect: function( event ) {
onSelect( event ) {
if ( this.props.homeLink ) {
return;
}
Expand All @@ -75,12 +76,20 @@ module.exports = React.createClass( {
event.preventDefault(); // this doesn't actually do anything...
},

starSite: function() {
starSite() {
const site = this.props.site;
sites.toggleStarred( site.ID );
},

renderStar: function() {
enableStarTooltip() {
this.setState( { starTooltip: true } );
},

disableStarTooltip() {
this.setState( { starTooltip: false } );
},

renderStar() {
const site = this.props.site;

if ( ! site || this.props.disableStarring ) {
Expand All @@ -93,8 +102,8 @@ module.exports = React.createClass( {
<button
className="site__star"
onClick={ this.starSite }
onMouseEnter={ () => this.setState( { starTooltip: true } ) }
onMouseLeave={ () => this.setState( { starTooltip: false } ) }
onMouseEnter={ this.enableStarTooltip }
onMouseLeave={ this.disableStarTooltip }
ref="starButton"
>
{ isStarred
Expand All @@ -112,7 +121,7 @@ module.exports = React.createClass( {
);
},

renderEditIcon: function() {
renderEditIcon() {
if ( ! userCan( 'manage_options', this.props.site ) ) {
return <SiteIcon site={ this.props.site } />;
}
Expand All @@ -131,28 +140,31 @@ module.exports = React.createClass( {
);
},

getHref: function() {
getHref() {
if ( this.state.showMoreActions || ! this.props.site ) {
return null;
}

return this.props.homeLink ? this.props.site.URL : this.props.href;
},

closeActions: function() {
closeActions() {
this.setState( { showMoreActions: false } );
},

render: function() {
var site = this.props.site,
siteClass;
toggleActions() {
this.setState( { showMoreActions: ! this.state.showMoreActions } );
},

render() {
const site = this.props.site;

if ( ! site ) {
// we could move the placeholder state here
return null;
}

siteClass = classNames( {
const siteClass = classnames( {
site: true,
'is-jetpack': site.jetpack,
'is-primary': site.primary,
Expand All @@ -165,54 +177,53 @@ module.exports = React.createClass( {

return (
<div className={ siteClass }>
{ ! this.state.showMoreActions ?
<a className="site__content"
href={ this.props.homeLink ? site.URL : this.props.href }
target={ this.props.externalLink && ! this.state.showMoreActions && '_blank' }
title={ this.props.homeLink
? this.translate( 'Visit "%(title)s"', { args: { title: site.title } } )
: site.title
}
onTouchTap={ this.onSelect }
onClick={ this.props.onClick }
onMouseEnter={ this.props.onMouseEnter }
onMouseLeave={ this.props.onMouseLeave }
aria-label={
this.translate( 'Open site %(domain)s in new tab', {
args: { domain: site.domain }
} )
}
>
<SiteIcon site={ site } />
<div className="site__info">
<div className="site__title">
{ this.props.site.is_private &&
<span className="site__badge">
<Gridicon icon="lock" size={ 14 } />
</span>
}
{ site.title }
{ ! this.state.showMoreActions
? <a className="site__content"
href={ this.props.homeLink ? site.URL : this.props.href }
target={ this.props.externalLink && ! this.state.showMoreActions && '_blank' }
title={ this.props.homeLink
? this.translate( 'Visit "%(title)s"', { args: { title: site.title } } )
: site.title
}
onTouchTap={ this.onSelect }
onClick={ this.props.onClick }
onMouseEnter={ this.props.onMouseEnter }
onMouseLeave={ this.props.onMouseLeave }
aria-label={
this.translate( 'Open site %(domain)s in new tab', {
args: { domain: site.domain }
} )
}
>
<SiteIcon site={ site } />
<div className="site__info">
<div className="site__title">
{ this.props.site.is_private &&
<span className="site__badge">
<Gridicon icon="lock" size={ 14 } nonStandardSize />
</span>
}
{ site.title }
</div>
<div className="site__domain">{ site.domain }</div>
</div>
{ this.props.homeLink &&
<span className="site__home">
<Gridicon icon="house" size={ 18 } />
</span>
}
{ ! this.props.disableStarring && sites.isStarred( this.props.site ) &&
<span className="site__badge">
<Gridicon icon="star" size={ 18 } />
</span>
}
</a>
: <div className="site__content">
{ this.renderEditIcon() }
<div className="site__actions">
{ this.renderStar() }
</div>
<div className="site__domain">{ site.domain }</div>
</div>
{ this.props.homeLink &&
<span className="site__home">
<Gridicon icon="house" size={ 18 } />
</span>
}
{ ! this.props.disableStarring && sites.isStarred( this.props.site ) &&
<span className="site__badge">
<Gridicon icon="star" size={ 18 } />
</span>
}
</a>
:
<div className="site__content">
{ this.renderEditIcon() }
<div className="site__actions">
{ this.renderStar() }
</div>
</div>
}
{ this.props.indicator
? <SiteIndicator site={ site } onSelect={ this.props.onSelect } />
Expand All @@ -221,7 +232,7 @@ module.exports = React.createClass( {
{ this.props.enableActions &&
<button
className="site__toggle-more-options"
onClick={ () => this.setState( { showMoreActions: ! this.state.showMoreActions } ) }
onClick={ this.toggleActions }
>
<Gridicon icon="ellipsis" size={ 24 } />
</button>
Expand Down