Skip to content

Commit 35228c2

Browse files
committed
Added Tech-Stack based filter
1 parent 09bea0a commit 35228c2

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ <h2><i class="fas fa-filter"></i> Filter Projects</h2>
7676
</div>
7777
<button class="btn-secondary" id="apply-filters">Apply Filters</button>
7878
<button class="btn-secondary" id="reset-filters">Reset</button>
79+
<div class="filter-group">
80+
<label>Filter by Tech Stack:</label>
81+
<div id="tag-filters" class="tag-filters">
82+
<!-- Dynamic tags will be appeared here -->
83+
</div>
84+
</div>
7985
</div>
8086
</div>
8187
</section>

script.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ const sampleProjects = [
8383

8484
// Store the current projects array
8585
let currentProjects = [...sampleProjects];
86+
let selectedTag = null;
87+
88+
//Store all the unique tags
89+
const allTagSet = new Set();
90+
sampleProjects.forEach(project => {
91+
project.tags.forEach(tag => allTagSet.add(tag));
92+
})
93+
94+
const uniqueTags = Array.from(allTagSet);
8695

8796
// DOM elements
8897
const projectsContainer = document.getElementById('projects-container');
@@ -95,13 +104,23 @@ const sampleProjects = [
95104
const resetFiltersBtn = document.getElementById('reset-filters');
96105
const searchInput = document.getElementById('search-input');
97106
const clearSearchBtn = document.getElementById('clear-search');
107+
const tagFiltersContainer = document.querySelector('.tag-filters');
108+
109+
uniqueTags.forEach(tag => {
110+
const button = document.createElement('button');
111+
button.textContent = tag;
112+
button.classList.add('tag-filter-btn')
113+
button.dataset.tag = tag
114+
tagFiltersContainer.appendChild(button)
115+
})
98116

99117
// Initialize the app
100118
function init() {
101119
setTimeout(() => {
102120
hideLoading();
103121
renderProjects(currentProjects);
104122
setupEventListeners();
123+
initializeTagFilterListener();
105124
}, 1000); // Simulate loading time
106125
}
107126

@@ -129,6 +148,28 @@ const sampleProjects = [
129148
});
130149
}
131150

151+
function initializeTagFilterListener() {
152+
tagFiltersContainer.addEventListener('click', (e) => {
153+
if (e.target.classList.contains('tag-filter-btn')) {
154+
const clickedTag = e.target.dataset.tag;
155+
156+
// Toggle selection
157+
if (selectedTag === clickedTag) {
158+
selectedTag = null;
159+
e.target.classList.remove('active');
160+
} else {
161+
selectedTag = clickedTag;
162+
// Remove active from all buttons
163+
document.querySelectorAll('.tag-filter-btn').forEach(btn => btn.classList.remove('active'));
164+
e.target.classList.add('active');
165+
}
166+
167+
applyFilters(); // Re-apply filters based on tag
168+
}
169+
});
170+
}
171+
172+
132173
// Render projects
133174
function renderProjects(projects) {
134175
if (projects.length === 0) {
@@ -248,6 +289,10 @@ const sampleProjects = [
248289
filtered = filtered.filter(p => p.hasReadme);
249290
}
250291

292+
if(selectedTag){
293+
filtered = filtered.filter(project => project.tags.includes(selectedTag));
294+
}
295+
251296
return filtered;
252297
}
253298

@@ -288,6 +333,8 @@ const sampleProjects = [
288333
hasReadmeFilter.checked = false;
289334
searchInput.value = '';
290335
clearSearchBtn.style.display = 'none';
336+
selectedTag = null;
337+
document.querySelectorAll('.tag-filter-btn').forEach(btn => btn.classList.remove('active'));
291338
renderProjects(sampleProjects);
292339
}
293340

style.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,28 @@
331331
transform: translateY(-2px);
332332
}
333333

334+
.tag-filters {
335+
display: flex;
336+
flex-wrap: wrap;
337+
gap: 8px;
338+
margin: 10px 0;
339+
}
340+
341+
.tag-filter-btn {
342+
padding: 6px 12px;
343+
background: #f0f0f0;
344+
border: 1px solid #ccc;
345+
border-radius: 20px;
346+
cursor: pointer;
347+
transition: background 0.3s;
348+
}
349+
350+
.tag-filter-btn.active {
351+
background: #007bff;
352+
color: #fff;
353+
border-color: #007bff;
354+
}
355+
334356
/* Projects section */
335357
.projects-section {
336358
padding: 2rem 0;

0 commit comments

Comments
 (0)