2019-08-22 11:36:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-11-21 08:08:47 +00:00
|
|
|
import { Fragment } from 'react';
|
2019-08-22 11:36:20 +00:00
|
|
|
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.
|
|
|
|
*/
|
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 (
|
2019-11-21 08:08:47 +00:00
|
|
|
<Fragment>
|
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'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
2019-11-21 08:08:47 +00:00
|
|
|
</Fragment>
|
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 );
|