Changeset 5024 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/widget-area/widgets/ratings/index.jsx
- Timestamp:
- 03/01/2017 06:08:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/client/components/widget-area/widgets/ratings/index.jsx
r4223 r5024 1 import React from 'react'; 2 import rangeRight from 'lodash/rangeRight'; 1 /** 2 * External dependencies. 3 */ 4 import React, { Component, PropTypes } from 'react'; 5 import { connect } from 'react-redux'; 6 import { identity } from 'lodash'; 7 import { localize } from 'i18n-calypso'; 8 import { rangeRight } from 'lodash'; 3 9 10 /** 11 * Internal dependencies. 12 */ 13 import { getPlugin } from 'state/selectors'; 4 14 import PluginRatings from 'components/plugin-ratings'; 5 15 6 export default React.createClass( { 7 displayName: 'RatingsWidget', 16 export class RatingsWidget extends Component { 17 static propTypes = { 18 plugin: PropTypes.object, 19 translate: PropTypes.func, 20 }; 21 22 static defaultProps = { 23 plugin: {}, 24 translate: identity, 25 }; 8 26 9 27 ratingsBreakdown() { 28 const { plugin, translate } = this.props; 29 30 if ( ! plugin.ratings.length ) { 31 return ( 32 <div className="rating"><p>{ translate( 'This plugin has not been rated yet.' ) }</p></div> 33 ); 34 } 35 10 36 return ( 11 37 <div> 12 <a className="reviews-link" href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/` }>See all</a> 38 <a className="reviews-link" href={ `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/` }> 39 { translate( 'See all' ) } 40 </a> 13 41 14 <PluginRatings rating={ this.props.plugin.rating } ratingCount={ this.props.plugin.num_ratings} />42 <PluginRatings rating={ plugin.meta.rating } ratingCount={ plugin.ratings.length } /> 15 43 16 44 <ul className="ratings-list"> 17 { rangeRight( 1, 6 ).map( stars => { 18 const barWidth = this.props.plugin.num_ratings ? 100 * this.props.plugin.ratings[ stars ] / this.props.plugin.num_ratings : 0; 45 { rangeRight( 1, 6 ).map( ( stars ) => { 46 const barWidth = plugin.ratings.length ? 100 * plugin.ratings[ stars ] / plugin.ratings.length : 0; 47 const link = `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/?filter=${ stars }`; 19 48 20 49 return ( 21 <li className="counter-container"> 22 <a href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/?filter=${ stars }` }> 23 <span className="counter-label">{ stars > 1 ? `${ stars } stars` : `${ stars } star` }</span> 50 <li key={ stars } className="counter-container"> 51 <a href={ link }> 52 <span className="counter-label"> 53 { translate( '1 star', '%(stars)s stars', { count: stars, args: { stars } } ) } 54 </span> 24 55 <span className="counter-back"> 25 56 <span className="counter-bar" style={ { width: `${ barWidth }%` } } /> 26 57 </span> 27 <span className="counter-count">{ this.props.plugin.ratings[ stars ] }</span>58 <span className="counter-count">{ plugin.ratings[ stars ] }</span> 28 59 </a> 29 60 </li> … … 33 64 </div> 34 65 ); 35 } ,66 } 36 67 37 68 render() { 69 const { plugin, translate } = this.props; 70 38 71 return ( 39 72 <div className="widget plugin-ratings"> 40 <h4 className="widget-title">Ratings</h4> 41 <meta itemProp="ratingCount" content={ this.props.plugin.num_ratings } /> 42 { this.props.plugin.num_ratings ? 43 this.ratingsBreakdown() : 44 <div className="rating"><p>This plugin has not been rated yet.</p></div> 45 } 73 <h4 className="widget-title">{ translate( 'Ratings' ) }</h4> 74 <meta itemProp="ratingCount" content={ plugin.ratings.length } /> 75 76 { this.ratingsBreakdown() } 77 46 78 <div className="user-rating"> 47 <a className="button button-secondary" href={ `https://wordpress.org/support/plugin/${ this.props.plugin.slug }/reviews/#new-post` }>Add my review</a> 79 <a 80 className="button button-secondary" 81 href={ `https://wordpress.org/support/plugin/${ plugin.slug }/reviews/#new-post` } 82 > 83 { translate( 'Add my review' ) } 84 </a> 48 85 </div> 49 86 </div> 50 ) 87 ); 51 88 } 52 } ); 89 } 90 91 export default connect( 92 ( state ) => ( { 93 plugin: getPlugin( state ), 94 } ), 95 )( localize( RatingsWidget ) );
Note: See TracChangeset
for help on using the changeset viewer.