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

feat(storefront): BCTHEME-304 add pagination for Wish Lists #1906

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -25,6 +25,7 @@
- Added styling config for the PayPal SPB on checkout page [#1866](https://github.com/bigcommerce/cornerstone/pull/1866)
- Moved zoomSize and productSize to the upper level, cause product.js is not availabe on the Quick View [#1884](https://github.com/bigcommerce/cornerstone/pull/1884)
- Added new region on the cart page [#1901](https://github.com/bigcommerce/cornerstone/pull/1901)
- Add pagination for Wishlists.[#1906](https://github.com/bigcommerce/cornerstone/pull/1906)

## 4.12.1 (11-10-2020)
- Write a Review modal cause TypeError. [#1899](https://github.com/bigcommerce/cornerstone/pull/1899)
Expand Down
24 changes: 24 additions & 0 deletions assets/js/theme/common/utils/pagination-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const changeWishlistPaginationLinks = (wishlistUrl, ...paginationItems) => $.each(paginationItems, (_, $item) => {
const paginationLink = $item.children('.pagination-link');

if ($item.length && !paginationLink.attr('href').includes('page=')) {
const pageNumber = paginationLink.attr('href');
paginationLink.attr('href', `${wishlistUrl}page=${pageNumber}`);
}
});

/**
* helps to withdraw differences in structures around the stencil resource pagination
*/
export const wishlistPaginatorHelper = () => {
const $paginationList = $('.pagination-list');

if (!$paginationList.length) return;

const $nextItem = $('.pagination-item--next', $paginationList);
const $prevItem = $('.pagination-item--previous', $paginationList);
const currentHref = $('[data-pagination-current-page-link]').attr('href');
const partialPaginationUrl = currentHref.split('page=').shift();

changeWishlistPaginationLinks(partialPaginationUrl, $prevItem, $nextItem);
};
5 changes: 5 additions & 0 deletions assets/js/theme/wishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'foundation-sites/js/foundation/foundation';
import 'foundation-sites/js/foundation/foundation.reveal';
import nod from './common/nod';
import PageManager from './page-manager';
import { wishlistPaginatorHelper } from './common/utils/pagination-utils';

export default class WishList extends PageManager {
constructor(context) {
Expand Down Expand Up @@ -60,6 +61,10 @@ export default class WishList extends PageManager {
onReady() {
const $addWishListForm = $('.wishlist-form');

if ($('[data-pagination-wishlist]').length) {
wishlistPaginatorHelper();
}

if ($addWishListForm.length) {
this.registerAddWishListValidation($addWishListForm);
}
Expand Down
1 change: 1 addition & 0 deletions templates/components/account/wishlist-item-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
</li>
{{/each}}
</ul>
{{> components/common/paginator wishlist.pagination}}
5 changes: 4 additions & 1 deletion templates/components/common/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
<a class="pagination-link"
href="{{this.url}}"
{{#unless reload}}data-faceted-search-facet{{/unless}}
{{#if this.number '==' ../current}}aria-current="page"{{/if}}
{{#if this.number '==' ../current}}
aria-current="page"
data-pagination-current-page-link
{{/if}}
aria-label="{{lang 'common.paginator.page_of' current=this.number total=../links.length}}"
>
{{this.number}}
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/account/wishlist-details.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#partial "page"}}
<div class="account">
<div class="account" data-pagination-wishlist>

{{#if wishlist.is_editable}}
{{> components/common/breadcrumbs breadcrumbs=breadcrumbs}}
Expand Down