2019-08-22 11:36:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-08-27 15:25:32 +00:00
|
|
|
import { ENABLE_REVIEW_RATING } from '@woocommerce/block-settings';
|
2019-08-22 11:36:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import LoadMoreButton from '../../base/components/load-more-button';
|
|
|
|
import ReviewOrderSelect from '../../base/components/review-order-select';
|
|
|
|
import ReviewList from '../../base/components/review-list';
|
|
|
|
import withReviews from '../../base/hocs/with-reviews';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Block rendered in the frontend.
|
|
|
|
*/
|
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;
|
|
|
|
|
|
|
|
if ( 0 === reviews.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-09-05 15:09:31 +00:00
|
|
|
{ attributes.showOrderby !== 'false' && ENABLE_REVIEW_RATING && (
|
2019-08-22 11:36:20 +00:00
|
|
|
<ReviewOrderSelect
|
|
|
|
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'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
2019-08-22 11:36:20 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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 );
|