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 sort products issue #241

Merged
merged 1 commit into from
Aug 21, 2023
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
3 changes: 2 additions & 1 deletion public/product.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/product.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
13 changes: 6 additions & 7 deletions src/assets/js/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
app.element('#product-filter').value = urlParams.get('sort');
}


// Sort Products
app.on('change', '#product-filter', event => {
let url = new URL(window.location.href);
url.searchParams.set('sort', event.currentTarget.value);
window.history.pushState({}, '', url);
productsList.sortBy = event.currentTarget.value;
app.on('change','#product-filter', async event =>{

Check failure on line 15 in src/assets/js/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/assets/js/products.js#L15

Async functions are not supported yet on Node 4.0.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy found a critical Error Prone issue: Async functions are not supported yet on Node 4.0.0.

The issue with the code is that it uses an async function, which is not supported in Node 4.0.0. To fix this, you can use a regular function instead of an async function. Here's the updated code:

Suggested change
app.on('change','#product-filter', async event =>{
app.on('change','#product-filter', function(event){
window.history.replaceState(null, null, salla.helpers.addParamToUrl('sort',event.currentTarget.value));
app.element('salla-products-list').sortBy=event.currentTarget.value;
app.element('salla-products-list').reload().then(() => {
app.element('salla-products-list').setAttribute('filters', `{"sort": "${event.currentTarget.value}"}`);
});
});

Note: This code suggestion assumes that the reload() method returns a promise. If it doesn't, you may need to modify the code accordingly.


This comment was generated by an experimental AI tool.

window.history.replaceState(null, null, salla.helpers.addParamToUrl('sort',event.currentTarget.value));

Check failure on line 16 in src/assets/js/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/assets/js/products.js#L16

You have a misspelled word: salla on Identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy found a critical Error Prone issue: You have a misspelled word: salla on Identifier

The issue with the code is that the identifier "salla" is misspelled. It should be "Salla" instead. To fix this, you need to change "salla.helpers.addParamToUrl" to "Salla.helpers.addParamToUrl" in the code.

Suggested change
window.history.replaceState(null, null, salla.helpers.addParamToUrl('sort',event.currentTarget.value));
window.history.replaceState(null, null, Salla.helpers.addParamToUrl('sort', event.currentTarget.value));

This comment was generated by an experimental AI tool.

app.element('salla-products-list').sortBy=event.currentTarget.value;
await app.element('salla-products-list').reload();

Check failure on line 18 in src/assets/js/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/assets/js/products.js#L18

Async functions are not supported yet on Node 4.0.0.

Check failure on line 18 in src/assets/js/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/assets/js/products.js#L18

You have a misspelled word: salla on String
Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy found a critical Error Prone issue: Async functions are not supported yet on Node 4.0.0.

The issue with the code is that it uses the await keyword inside a non-async function. Since the function is not declared as async, the use of await is not valid and will result in a syntax error.

To fix this issue, you can either declare the function as async or use a .then() method to handle the asynchronous operation.

Here's the updated code:

// Set Sort
if (urlParams.has('sort')) {
    app.element('#product-filter').value = urlParams.get('sort');
}

// Sort Products
app.on('change','#product-filter', event =>{
    window.history.replaceState(null, null, salla.helpers.addParamToUrl('sort',event.currentTarget.value));
    app.element('salla-products-list').sortBy=event.currentTarget.value;
    app.element('salla-products-list').reload()
        .then(() => {
            app.element('salla-products-list').setAttribute('filters', `{"sort": "${event.currentTarget.value}"}`);
        });
});

salla.event.once('salla-products-list::products.fetched', res=>{
    res.title && (app.element('#page-main-title').innerHTML = res.title);
});

this.initiateMobileMenu();

Note: This code assumes that reload() method returns a Promise. If it doesn't, you may need to modify the code accordingly.


This comment was generated by an experimental AI tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy found a critical Error Prone issue: You have a misspelled word: salla on String

Suggested change
await app.element('salla-products-list').reload();
await app.element('salla-products-list').reload();
```

Issue description: The code has a misspelled word "salla" in the string. It should be corrected to "salla-products-list".


This comment was generated by an experimental AI tool.

app.element('salla-products-list').setAttribute('filters', `{"sort": "${event.currentTarget.value}"}`)

Check failure on line 19 in src/assets/js/products.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/assets/js/products.js#L19

You have a misspelled word: salla on String
Copy link
Contributor

Choose a reason for hiding this comment

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

Codacy found a critical Error Prone issue: You have a misspelled word: salla on String

The code you provided has a misspelled word in the string. The correct spelling should be "sala" instead of "salla". To fix it, you need to update the code to use the correct spelling. Here's the corrected code:

Suggested change
app.element('salla-products-list').setAttribute('filters', `{"sort": "${event.currentTarget.value}"}`)
app.element('sala-products-list').setAttribute('filters', `{"sort": "${event.currentTarget.value}"}`);

Please note that I have replaced "salla" with "sala" in the code.


This comment was generated by an experimental AI tool.

});

salla.event.once('salla-products-list::products.fetched', res=>{
res.title && (app.element('#page-main-title').innerHTML = res.title);
});
Expand Down
Loading