Skip to content

Commit 324c35b

Browse files
committed
add: integrated DifficultyDropdown class into options.js
1 parent 984bb2c commit 324c35b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

options/options.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ document.addEventListener('DOMContentLoaded', () => {
2020
const searchInput = document.getElementById('searchInput');
2121
const tagDropdownContainer = document.getElementById('tagDropdownContainer');
2222
let tagDropdownInstance = null;
23+
const difficultyDropdownContainer = document.getElementById('difficultyDropdownContainer');
24+
let difficultyDropdownInstance = null;
2325

2426
function renderProblems(problems, filterTag, searchTerm, sortOrder = 'recent-desc') {
2527
problemsList.innerHTML = '';
2628
let filtered = problems;
2729
if (filterTag && filterTag !== 'all') {
2830
filtered = filtered.filter(p => Array.isArray(p.tags) && p.tags.includes(filterTag));
2931
}
32+
33+
if (filterDifficulty && filterDifficulty == 'all') {
34+
filtered = filtered.filter(p => difficulty === filterDifficulty);
35+
}
36+
3037
if (searchTerm) {
3138
filtered = filtered.filter(p => p.title.toLowerCase().includes(searchTerm.toLowerCase()));
3239
}
@@ -81,20 +88,30 @@ document.addEventListener('DOMContentLoaded', () => {
8188
}
8289
});
8390
const allTags = Array.from(tagSet).sort((a, b) => a.localeCompare(b));
84-
let currentProblems = problems; // Store for re-sorting/filtering
91+
const allDifficulties = ['Easy', 'Medium', 'Hard'];
92+
let currentProblems = problems;
8593
function rerender() {
8694
renderProblems(
8795
currentProblems,
8896
tagDropdownInstance ? tagDropdownInstance.selectedTag : 'all',
97+
difficultyDropdownInstance ? difficultyDropdownInstance.selectedDifficulty : 'all',
8998
searchInput.value,
9099
sortDropdown.value
91100
);
92101
}
102+
93103
if (tagDropdownInstance) {
94104
tagDropdownInstance.setTags(allTags);
95105
} else {
96106
tagDropdownInstance = new window.TagDropdown(tagDropdownContainer, allTags, () => rerender());
97107
}
108+
109+
if (difficultyDropdownInstance) {
110+
difficultyDropdownInstance.setDifficulty(allDifficulties);
111+
} else {
112+
difficultyDropdownInstance = new window.DifficultyDropdown(difficultyDropdownContainer, allDifficulties, () => rerender());
113+
}
114+
98115
// Initial render
99116
rerender();
100117
// Event listeners

0 commit comments

Comments
 (0)