Skip to content

Commit 6addd7e

Browse files
authored
Merge pull request #246 from Ishuuu1213/Filter-Functionality
✨ Added Search and Multi-Filter Functionality with Clear Button on Challenges Page
2 parents 85154ec + 7c2d05c commit 6addd7e

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

LEADERBOARD.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This leaderboard tracks contributors who have completed issues labeled as `level
66

77
| Username | Level 1 | Level 2 | Level 3 | PRs Merged |
88
|----------|---------|---------|---------|-------------|
9+
910
| [@Suhani1234-5](https://github.com/Suhani1234-5) | 0 | 1 | 1 | 5 |
1011
| [@cosmicTitiksha](https://github.com/cosmicTitiksha) | 1 | 1 | 0 | 4 |
1112
| [@Shalini22-ui](https://github.com/Shalini22-ui) | 0 | 1 | 0 | 4 |
@@ -39,6 +40,7 @@ This leaderboard tracks contributors who have completed issues labeled as `level
3940
| [@faisal07777](https://github.com/faisal07777) | 1 | 0 | 0 | 0 |
4041
| [@AmritRaj29](https://github.com/AmritRaj29) | 1 | 0 | 0 | 0 |
4142

43+
4244
---
4345

4446
**Legend:**

pages/challenges.html

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ <h1 class="challenges-hero__title">
6262
<!-- Filter Controls -->
6363
<section class="challenges-filter" aria-labelledby="filters-heading">
6464
<div class="container filter-controls">
65+
<div class="filter-group">
66+
67+
</div>
68+
6569
<h2 id="filters-heading" class="visually-hidden">Filter Challenges</h2>
6670

6771
<div class="filter-group">
@@ -88,14 +92,15 @@ <h2 id="filters-heading" class="visually-hidden">Filter Challenges</h2>
8892
</select>
8993
</div>
9094

91-
<div class="search-group" style="margin-left:auto;">
95+
<div class="search-group" style="display: flex; gap: 0.5rem; margin-left: auto;">
9296
<input
9397
type="search"
9498
id="search-challenges"
9599
class="search-input"
96100
placeholder="Search challenges..."
97101
aria-label="Search coding challenges by title or tag"
98102
/>
103+
<button id="clearFilters" class="btn btn-secondary">Clear Filters</button>
99104
</div>
100105
</div>
101106
</section>
@@ -279,6 +284,59 @@ <h4>Community</h4>
279284
localStorage.setItem('theme', newTheme);
280285
});
281286
</script>
287+
<script>
288+
const searchInput = document.getElementById("search-challenges");
289+
const difficultyFilter = document.getElementById("difficulty-filter");
290+
const categoryFilter = document.getElementById("category-filter");
291+
const challengesList = document.getElementById("challengesList");
292+
const noResults = document.getElementById("no-results");
293+
294+
const challengeCards = Array.from(challengesList.getElementsByClassName("challenge-card"));
295+
296+
function filterChallenges() {
297+
const searchTerm = searchInput.value.toLowerCase();
298+
const difficulty = difficultyFilter.value;
299+
const category = categoryFilter.value;
300+
301+
let visibleCount = 0;
302+
303+
challengeCards.forEach(card => {
304+
const title = card.querySelector(".challenge-card__title").textContent.toLowerCase();
305+
const cardDifficulty = card.dataset.difficulty;
306+
const cardCategory = card.dataset.category;
307+
308+
const matchesSearch = title.includes(searchTerm);
309+
const matchesDifficulty = !difficulty || cardDifficulty === difficulty;
310+
const matchesCategory = !category || cardCategory === category;
311+
312+
const isVisible = matchesSearch && matchesDifficulty && matchesCategory;
313+
314+
card.style.display = isVisible ? "block" : "none";
315+
316+
if (isVisible) visibleCount++;
317+
});
318+
319+
noResults.style.display = visibleCount === 0 ? "block" : "none";
320+
}
321+
322+
// Event listeners for real-time filtering
323+
searchInput.addEventListener("input", filterChallenges);
324+
difficultyFilter.addEventListener("change", filterChallenges);
325+
categoryFilter.addEventListener("change", filterChallenges);
326+
const clearBtn = document.getElementById("clearFilters");
327+
328+
clearBtn.addEventListener("click", () => {
329+
// Reset all filters
330+
searchInput.value = "";
331+
difficultyFilter.value = "";
332+
categoryFilter.value = "";
333+
334+
// Re-run the filtering function to show all challenges again
335+
filterChallenges();
336+
});
337+
338+
</script>
339+
282340

283341
</body>
284342
</html>

styles/challenges.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,5 @@ body {
509509
font-size: 2rem;
510510
}
511511
}
512+
513+

0 commit comments

Comments
 (0)