Skip to content

Commit 6f1c05a

Browse files
committed
✏️ - Add more comments and delete consoles logs
1 parent 09c2822 commit 6f1c05a

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

js/app.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ document.addEventListener('DOMContentLoaded', function () { // On document load,
1313
});
1414

1515
function addToCart(id) { // Add product to cart function
16-
console.log(`Tu as ajouté le produit ${id}`); // Console log the product i
17-
1816
let product = getProductDetails(Number(id)); // Get the product details
1917

2018
if (product.stock <= 0) { // If stock is 0 or less
@@ -24,7 +22,6 @@ function addToCart(id) { // Add product to cart function
2422
product.stock--; // Decrease 1 to the product in cart
2523
document.querySelector(`.stock-${product.id}`).innerHTML = product.stock; // Display the new stock
2624
}
27-
2825
// Check if product is already in cart
2926
const productCartName = `inCart-${product.id}`; // Set the product cart name
3027
let cart = localStorage.getItem(productCartName); // Get the product cart
@@ -35,7 +32,6 @@ function addToCart(id) { // Add product to cart function
3532
localStorage.setItem(productCartName, JSON.stringify(cart)); // Set the product cart
3633

3734
// Update the cart
38-
console.log(product.slug + '-inCart'); // Console log the product slug
3935
document.querySelector(`.${product.slug}-inCart`).innerHTML = cart.productsInCart; // Update the product in cart
4036

4137
} else { // If the product cart doesn't exist
@@ -50,7 +46,7 @@ function addToCart(id) { // Add product to cart function
5046
}
5147

5248
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53-
// All Functions
49+
// All Functions UwU
5450
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5551

5652
function notification(message, type='success') { // Function to show notification
@@ -142,7 +138,6 @@ document.addEventListener('click', function (e) { // On click, execute the follo
142138

143139
if (getItem !== null) { // Check if the product is already in the cart
144140
COURSES[i].stock += getItem.productsInCart; // Increment the quantity of the product in stock
145-
console.log("Stock " + COURSES[i].stock);
146141

147142
document.querySelector(`.stock-${COURSES[i].id}`).innerHTML = COURSES[i].stock; // Display the new stock
148143
}
@@ -158,31 +153,30 @@ document.addEventListener('click', function (e) { // On click, execute the follo
158153
// your cart //
159154
//-------------------------------------------------//
160155

161-
let idTrash = e.target.parentNode.parentNode.dataset.id; // Get the product id
162-
let product = getProductDetails(Number(idTrash)); // Get the product details
156+
let product = getProductDetails(Number(e.target.parentNode.parentNode.dataset.id)); // Get the product details
163157

164158
product.stock++; // Add 1 to the product stock
165-
document.querySelector(`.stock-${idTrash}`).innerHTML = product.stock; // Display the new stock
159+
document.querySelector(`.stock-${product.id}`).innerHTML = product.stock; // Display the new stock
166160

167-
let getItem = JSON.parse(localStorage.getItem(`inCart-${idTrash}`)); // See how many times the product is in the cart
161+
let getItem = JSON.parse(localStorage.getItem(`inCart-${product.id}`)); // See how many times the product is in the cart
168162

169163
if (getItem.productsInCart <= 1) { // If only 1 product is in the cart
170-
localStorage.removeItem(`inCart-${idTrash}`); // Remove the product from the localStorage
164+
localStorage.removeItem(`inCart-${product.id}`); // Remove the product from the localStorage
171165
document.querySelector(`.${e.target.parentNode.parentNode.classList[0]}`).remove(); // Remove the product from the cart
172166
notification(`${product.title} à totalement été supprimé du panier`, `danger`); // Alert the user with notification
173167
} else { // Otherwise
174168
getItem.productsInCart--; // Decrease 1 to the product in cart
175-
localStorage.setItem(`inCart-${idTrash}`, JSON.stringify(getItem)); // Remove the product from the localStorage
169+
localStorage.setItem(`inCart-${product.id}`, JSON.stringify(getItem)); // Remove the product from the localStorage
176170
document.querySelector(`.${product.slug}-inCart`).innerHTML = getItem.productsInCart; // Remove the product from the cart
177171
notification(`1 cours "${product.title}" à été supprimé du panier`, `danger`); // Alert the user with notification
178172
}
179173
} else if (e.target.classList.contains('noteOrdre')) { // If the user clicks on the noteOrdre button, execuse the following code
180-
filtre("noteCroissant");
174+
filtre("noteCroissant"); // Sort the products by note
181175
} else if (e.target.classList.contains('noteDesordre')) { // If the user clicks on the noteDesordre button, execuse the following code
182-
filtre("noteDecroissant");
176+
filtre("noteDecroissant"); // Sort the products by note
183177
} else if (e.target.classList.contains('prixOrdre')) { // If the user clicks on the prixOrdre button, execuse the following code
184-
filtre("prixCroissant");
178+
filtre("prixCroissant"); // Sort the products by price
185179
} else if (e.target.classList.contains('prixDesordre')) { // If the user clicks on the prixDesordre button, execuse the following code
186-
filtre("prixDecroissant");
180+
filtre("prixDecroissant"); // Sort the products by price
187181
}
188182
});

js/search.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ document.querySelector('form.search-form input').addEventListener('input', funct
2323
}
2424
});
2525

26-
function filtre(type) {
27-
if(type === "noteCroissant"){
28-
COURSES.sort((a, b) => a.mark - b.mark)
29-
} else if(type === "noteDecroissant"){
30-
COURSES.sort((a, b) => b.mark - a.mark)
31-
} else if(type === "prixCroissant"){
32-
COURSES.sort((a, b) => a.price - b.price)
33-
} else if(type === "prixDecroissant"){
34-
COURSES.sort((a, b) => b.price - a.price)
26+
function filtre(type) { // Search filter function
27+
if(type === "noteCroissant"){ // If the filter is note croissant
28+
COURSES.sort((a, b) => a.mark - b.mark) // Sort the courses by note
29+
} else if(type === "noteDecroissant"){ // If the filter is note decroissant
30+
COURSES.sort((a, b) => b.mark - a.mark) // Sort the courses by note
31+
} else if(type === "prixCroissant"){ // If the filter is prix croissant
32+
COURSES.sort((a, b) => a.price - b.price) // Sort the courses by price
33+
} else if(type === "prixDecroissant"){ // If the filter is prix decroissant
34+
COURSES.sort((a, b) => b.price - a.price) // Sort the courses by price
3535
}
3636

37-
document.querySelector('.courses__container').innerHTML = "";
37+
document.querySelector('.courses__container').innerHTML = ""; // Clear products
3838
showAllProducts('.courses__container', COURSES); // Show all products
3939
}

0 commit comments

Comments
 (0)