Skip to content

Commit 5e5acc3

Browse files
Loule95450Getsugo
andcommitted
πŸ™…β€β™€οΈ - Add filter on search bar
Co-Authored-By: Antony <91181127+Getsugo@users.noreply.github.com>
1 parent 01ffbd4 commit 5e5acc3

4 files changed

Lines changed: 87 additions & 2 deletions

File tree

β€Žcss/styles.cssβ€Ž

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,60 @@ header .submenu:hover #cart::-webkit-scrollbar-thumb:hover {background: #555;}
271271
font-size: 13px;
272272
}
273273

274+
/*drop*/
275+
276+
277+
/* Style The Dropdown Button */
278+
279+
.dropbtn {
280+
/* padding: 16px; */
281+
font-size: 16px;
282+
}
283+
284+
285+
/* The container <div> - needed to position the dropdown content */
286+
287+
.dropdown {
288+
position: relative;
289+
display: inline-block;
290+
}
291+
292+
293+
/* Dropdown Content (Hidden by Default) */
294+
295+
.dropdown-content {
296+
display: none;
297+
position: absolute;
298+
background-color: #f9f9f9;
299+
min-width: 160px;
300+
box-shadow: 0px 8px 16px 0px #555;
301+
z-index: 1;
302+
}
303+
304+
305+
/* Links inside the dropdown */
306+
307+
.dropdown-content a {
308+
color: #555;
309+
padding: 12px 16px;
310+
text-decoration: none;
311+
display: block;
312+
}
313+
314+
315+
/* Change color of dropdown links on hover */
316+
317+
.dropdown-content a:hover {
318+
background-color: #f1f1f1
319+
}
320+
321+
322+
/* Show the dropdown menu on hover */
323+
324+
.dropdown:hover .dropdown-content {
325+
display: block;
326+
}
327+
274328
/*
275329
* Footer
276330
*/

β€Žindex.htmlβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050

5151
<form id="search-item" class="search-form">
5252
<input type="text" onkeyup="search_cours()" placeholder="Rechercher ...">
53+
<div class="dropdown">
54+
<button class="dropbtn" id=myBtn>Filtre</button>
55+
56+
<div class="dropdown-content">
57+
<a class="a-dropdown-item noteOrdre" id="noteCroix">note : par ordre croissant</a>
58+
<a class="a-dropdown-item noteDesordre" id="noteDecroix">note : par ordre dΓ©croissant</a>
59+
<a class="a-dropdown-item prixOrdre" id="prixCroix">prix : par ordre croissant</a>
60+
<a class="a-dropdown-item prixDesordre" id="prixDecroix">prix : par ordre dΓ©croissant</a>
61+
62+
</div>
63+
</div>
5364
</form>
5465

5566
<div id="courses-list">

β€Žjs/app.jsβ€Ž

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ document.addEventListener('click', function (e) { // On click, execute the follo
173173
localStorage.setItem(`inCart-${idTrash}`, JSON.stringify(getItem)); // Remove the product from the localStorage
174174
document.querySelector(`.${product.slug}-inCart`).innerHTML = getItem.productsInCart; // Remove the product from the cart
175175
}
176-
} else if (e.target.classList.contains('ordre')){
177-
176+
} else if (e.target.classList.contains('noteOrdre')) { // If the user clicks on the noteOrdre button, execuse the following code
177+
filtre("noteCroissant");
178+
} else if (e.target.classList.contains('noteDesordre')) { // If the user clicks on the noteDesordre button, execuse the following code
179+
filtre("noteDecroissant");
180+
} else if (e.target.classList.contains('prixOrdre')) { // If the user clicks on the prixOrdre button, execuse the following code
181+
filtre("prixCroissant");
182+
} else if (e.target.classList.contains('prixDesordre')) { // If the user clicks on the prixDesordre button, execuse the following code
183+
filtre("prixDecroissant");
178184
}
179185
});

β€Žjs/search.jsβ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +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)
35+
}
36+
37+
document.querySelector('.courses__container').innerHTML = "";
38+
showAllProducts('.courses__container', COURSES); // Show all products
39+
}

0 commit comments

Comments
Β (0)