2019-08-22 11:36:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-13 17:13:11 +00:00
|
|
|
import { REVIEW_RATINGS_ENABLED } from '@woocommerce/block-settings';
|
2019-10-06 12:36:15 +00:00
|
|
|
import LoadMoreButton from '@woocommerce/base-components/load-more-button';
|
2020-03-30 13:04:27 +00:00
|
|
|
import {
|
|
|
|
ReviewList,
|
|
|
|
ReviewSortSelect,
|
|
|
|
} from '@woocommerce/base-components/reviews';
|
2019-10-06 12:36:15 +00:00
|
|
|
import withReviews from '@woocommerce/base-hocs/with-reviews';
|
2019-08-22 11:36:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Block rendered in the frontend.
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {Object} props.attributes Incoming block attributes.
|
|
|
|
* @param {function(any):any} props.onAppendReviews Function called when appending review.
|
|
|
|
* @param {function(any):any} props.onChangeOrderby
|
|
|
|
* @param {Array} props.reviews
|
|
|
|
* @param {number} props.totalReviews
|
2019-08-22 11:36:20 +00:00
|
|
|
*/
|
2019-09-05 15:09:31 +00:00
|
|
|
const FrontendBlock = ( {
|
|
|
|
attributes,
|
|
|
|
onAppendReviews,
|
|
|
|
onChangeOrderby,
|
|
|
|
reviews,
|
|
|
|
totalReviews,
|
|
|
|
} ) => {
|
2019-08-22 11:36:20 +00:00
|
|
|
const { orderby } = attributes;
|
|
|
|
|
2019-11-07 14:45:45 +00:00
|
|
|
if ( reviews.length === 0 ) {
|
2019-08-22 11:36:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-12-14 11:54:34 +00:00
|
|
|
<>
|
2019-12-13 17:13:11 +00:00
|
|
|
{ attributes.showOrderby !== 'false' && REVIEW_RATINGS_ENABLED && (
|
2019-10-28 13:53:09 +00:00
|
|
|
<ReviewSortSelect
|
2019-08-22 11:36:20 +00:00
|
|
|
defaultValue={ orderby }
|
|
|
|
onChange={ onChangeOrderby }
|
|
|
|
/>
|
|
|
|
) }
|
2019-09-05 15:09:31 +00:00
|
|
|
<ReviewList attributes={ attributes } reviews={ reviews } />
|
|
|
|
{ attributes.showLoadMore !== 'false' &&
|
|
|
|
totalReviews > reviews.length && (
|
|
|
|
<LoadMoreButton
|
|
|
|
onClick={ onAppendReviews }
|
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Load more reviews',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
2020-12-14 11:54:34 +00:00
|
|
|
</>
|
2019-08-22 11:36:20 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
FrontendBlock.propTypes = {
|
|
|
|
/**
|
|
|
|
* The attributes for this block.
|
|
|
|
*/
|
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
onAppendReviews: PropTypes.func,
|
|
|
|
onChangeArgs: PropTypes.func,
|
|
|
|
// from withReviewsattributes
|
|
|
|
reviews: PropTypes.array,
|
|
|
|
totalReviews: PropTypes.number,
|
|
|
|
};
|
|
|
|
|
2019-08-27 10:24:50 +00:00
|
|
|
export default withReviews( FrontendBlock );
|