Changeset 4467 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/favorite-button/button.jsx
- Timestamp:
- 12/04/2016 05:14:43 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/plugin/favorite-button/button.jsx
r4223 r4467 1 1 import React from 'react'; 2 import { connect } from 'react-redux'; 3 import includes from 'lodash/includes'; 2 4 3 export defaultReact.createClass( {5 const FavoriteButton = React.createClass( { 4 6 displayName: 'FavoriteButton', 5 7 6 getInitialState: function() {7 return {8 favorite: this.props.initialFavorite9 };10 },11 12 8 toggleFavorite( event ) { 13 const component = this, 14 $button = jQuery( event.target ); 9 const $button = jQuery( event.target ); 15 10 16 11 this.props.toggleFavorite( event ); … … 18 13 $button.addClass( 'is-animating' ).one( 'animationend', function() { 19 14 $button.toggleClass( 'is-animating favorited' ); 20 component.setState( { favorite: ! component.state.favorite } );21 15 } ); 22 16 }, … … 25 19 let classNames = [ 'plugin-favorite-heart' ]; 26 20 27 if ( this. state.favorite ) {21 if ( this.props.favorite ) { 28 22 classNames.push( 'favorited' ); 29 23 } … … 32 26 <div className="plugin-favorite"> 33 27 <button type="button" className={ classNames.join( ' ' ) } onClick={ this.toggleFavorite } > 34 <span className="screen-reader-text">{ `Favorite ${ this.props.plugin.name }` }</span> 28 <span className="screen-reader-text"> 29 { this.props.favorite 30 ? `Unfavorite ${ this.props.plugin.name }` 31 : `Favorite ${ this.props.plugin.name }` 32 } 33 </span> 35 34 </button> 36 35 </div> … … 38 37 } 39 38 } ); 39 40 export default connect( 41 ( state, { plugin } ) => ( { 42 favorite: includes( state.favorites, plugin.slug ) 43 } ), 44 )( FavoriteButton );
Note: See TracChangeset
for help on using the changeset viewer.