Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storefront): Reviews pagination navigation buttons reload page and does not open the Reviews tab #2048

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Reviews pagination navigation buttons reload page and does not open the Reviews tab. [#2048](https://github.com/bigcommerce/cornerstone/pull/2048)

## 5.7.0 (07-01-2021)
- Implement CEV language files into Cornerstone. [#2084](https://github.com/bigcommerce/cornerstone/pull/2084)
Expand Down
4 changes: 4 additions & 0 deletions assets/js/theme/global/quick-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'foundation-sites/js/foundation/foundation';
import 'foundation-sites/js/foundation/foundation.dropdown';
import utils from '@bigcommerce/stencil-utils';
import Review from '../product/reviews';
import ProductDetails from '../common/product-details';
import { defaultModal, ModalEvents } from './modal';
import 'slick-carousel';
Expand Down Expand Up @@ -41,6 +42,9 @@ export default function (context) {
}
}

/* eslint-disable no-new */
new Review({ $context: modal.$content });

return new ProductDetails(modal.$content.find('.quickView'), context);
});
});
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class Product extends PageManager {

if ($reviewForm.length === 0) return;

const review = new Review($reviewForm);
const review = new Review({ $reviewForm });

$('body').on('click', '[data-reveal-id="modal-review-form"]', () => {
validator = review.registerValidation(this.context);
Expand Down
59 changes: 39 additions & 20 deletions assets/js/theme/product/reviews.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
import nod from '../common/nod';
import { CollapsibleEvents } from '../common/collapsible';
import collapsibleFactory, { CollapsibleEvents } from '../common/collapsible';
import forms from '../common/models/forms';
import { safeString } from '../common/utils/safe-string';
import { announceInputErrorMessage } from '../common/utils/form-utils';

export default class {
constructor($reviewForm) {
this.validator = nod({
submit: $reviewForm.find('input[type="submit"]'),
tap: announceInputErrorMessage,
});
constructor({ $reviewForm, $context }) {
if ($reviewForm && $reviewForm.length) {
this.validator = nod({
submit: $reviewForm.find('input[type="submit"]'),
tap: announceInputErrorMessage,
});
}

this.$reviewsContent = $('#product-reviews');
this.$context = $context;
this.$reviewTabLink = $('.productView-reviewTabLink', this.$context);
BC-tymurbiedukhin marked this conversation as resolved.
Show resolved Hide resolved
this.$reviewsContent = $('#product-reviews', this.$context);
this.$reviewsContentList = $('#productReviews-content', this.$reviewsContent);
this.$collapsible = $('[data-collapsible]', this.$reviewsContent);

this.initLinkBind();
if (this.$context) {
collapsibleFactory('[data-collapsible]', { $context });
} else {
this.initLinkBind();
yurytut1993 marked this conversation as resolved.
Show resolved Hide resolved
}

this.injectPaginationLink();
this.collapseReviews();
this.setupReviews();
}

/**
* On initial page load, the user clicks on "(12 Reviews)" link
* The browser jumps to the review page and should expand the reviews section
*/
initLinkBind() {
const $content = $('#productReviews-content', this.$reviewsContent);

$('#productReview_link').on('click', () => {
$('.productView-reviewTabLink').trigger('click');
if (!$content.hasClass('is-open')) {
this.$collapsible.trigger(CollapsibleEvents.click);
}
});
const $productReviewLink = $('#productReview_link');
$productReviewLink
.attr('href', `${$productReviewLink.attr('href')}${window.location.search}#product-reviews`)
.on('click', () => this.expandReviews());
}

collapseReviews() {
// We're in paginating state, do not collapse
if (window.location.hash && window.location.hash.indexOf('#product-reviews') === 0) {
setupReviews() {
// We're in paginating state, reviews should be visible
if (
window.location.hash
&& window.location.hash.indexOf('#product-reviews') === 0
&& this.$reviewsContent.parents('.quickView').length === 0
) {
this.expandReviews();
return;
}

// force collapse on page load
this.$collapsible.trigger(CollapsibleEvents.click);
}

expandReviews() {
this.$reviewTabLink.trigger('click');

if (!this.$reviewsContentList.hasClass('is-open')) {
this.$collapsible.trigger(CollapsibleEvents.click);
}
}

/**
* Inject ID into the pagination link
*/
Expand Down
2 changes: 1 addition & 1 deletion templates/components/products/product-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h2 class="productView-brand"{{#if schema}} itemprop="brand" itemscope itemtype=
{{/if}}
{{> components/products/ratings rating=product.rating}}
{{#if product.num_reviews '>' 0}}
<a href="{{product.url}}#product-reviews" id="productReview_link">
<a href="{{product.url}}{{#if is_ajax}}#product-reviews{{/if}}" id="productReview_link">
{{lang 'products.reviews.link_to_review' total=product.num_reviews}}
</a>
{{else}}
Expand Down
4 changes: 4 additions & 0 deletions templates/components/products/quick-view.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<div class="modal-body quickView">
{{> components/products/product-view schema=false}}

{{#all settings.show_product_reviews theme_settings.show_product_reviews (if theme_settings.show_product_details_tabs '!==' true)}}
{{> components/products/reviews reviews=product.reviews product=product urls=urls}}
{{/all}}
</div>
2 changes: 1 addition & 1 deletion templates/components/products/reviews.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h5 itemprop="name" class="productReview-title">{{{ sanitize title }}}</h5>
</li>
{{/each}}
</ul>
{{> components/common/paginator pagination.reviews}}
{{> components/common/paginator pagination.reviews reload=true}}
</div>
</section>
{{/if}}