Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix(composables): category default query params (#309)
Browse files Browse the repository at this point in the history
* fix: proper filters, pagination and sorting reset on route chage

* fix: proper filters, pagination and sorting reset on route chage
  • Loading branch information
mkucmus authored and patzick committed Jan 21, 2020
1 parent f2b42c2 commit e59d96a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
16 changes: 6 additions & 10 deletions packages/composables/src/hooks/useProductListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ export const useProductListing = (
sharedListing.products = initialProducts;
selectedCriteria.sorting = activeSorting.value;

const resetFilters = async () => {
const resetFilters = () => {
selectedCriteria.filters = {};
};

const resetSorting = async () => {
const resetSorting = () => {
selectedCriteria.sorting = activeSorting.value;
};

const resetPagination = async () => {
selectedCriteria.pagination = {};
};

const toggleFilter = (
filter: EqualsFilter | EqualsAnyFilter | ContainsFilter, // TODO: handle range filter case as well
forceSave: boolean = false
Expand Down Expand Up @@ -165,14 +161,14 @@ export const useProductListing = (
await search();
};

if (sharedListing.products.length) {
// if reloaded on route change
if (initialProducts.length) {
resetFilters();
resetSorting();
resetPagination();
search();
changePagination(1);
}

const pagination: any = computed(() => sharedPagination);
const pagination: any = computed(() => localPagination);
const products = computed(() => localListing.products);
const productsTotal = computed(() => localPagination.total);
const selectedFilters = computed(() => localCriteria.filters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ export default {
}
},
watch: {
sortBy(value){
this.changeSorting(value)
sortBy(newSorting, oldOne){
// prevent reloading on default sorting
if (oldOne.name !== newSorting.name) {
this.changeSorting(newSorting)
}
}
},
computed: {
Expand Down

1 comment on commit e59d96a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for website ready!

Built with commit e59d96a

https://shopware-pwa-pxoazhrs0.now.sh

Please sign in to comment.