@@ -20,13 +20,20 @@ document.addEventListener('DOMContentLoaded', () => {
20
20
const searchInput = document . getElementById ( 'searchInput' ) ;
21
21
const tagDropdownContainer = document . getElementById ( 'tagDropdownContainer' ) ;
22
22
let tagDropdownInstance = null ;
23
+ const difficultyDropdownContainer = document . getElementById ( 'difficultyDropdownContainer' ) ;
24
+ let difficultyDropdownInstance = null ;
23
25
24
26
function renderProblems ( problems , filterTag , searchTerm , sortOrder = 'recent-desc' ) {
25
27
problemsList . innerHTML = '' ;
26
28
let filtered = problems ;
27
29
if ( filterTag && filterTag !== 'all' ) {
28
30
filtered = filtered . filter ( p => Array . isArray ( p . tags ) && p . tags . includes ( filterTag ) ) ;
29
31
}
32
+
33
+ if ( filterDifficulty && filterDifficulty == 'all' ) {
34
+ filtered = filtered . filter ( p => difficulty === filterDifficulty ) ;
35
+ }
36
+
30
37
if ( searchTerm ) {
31
38
filtered = filtered . filter ( p => p . title . toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) ) ) ;
32
39
}
@@ -81,20 +88,30 @@ document.addEventListener('DOMContentLoaded', () => {
81
88
}
82
89
} ) ;
83
90
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 ;
85
93
function rerender ( ) {
86
94
renderProblems (
87
95
currentProblems ,
88
96
tagDropdownInstance ? tagDropdownInstance . selectedTag : 'all' ,
97
+ difficultyDropdownInstance ? difficultyDropdownInstance . selectedDifficulty : 'all' ,
89
98
searchInput . value ,
90
99
sortDropdown . value
91
100
) ;
92
101
}
102
+
93
103
if ( tagDropdownInstance ) {
94
104
tagDropdownInstance . setTags ( allTags ) ;
95
105
} else {
96
106
tagDropdownInstance = new window . TagDropdown ( tagDropdownContainer , allTags , ( ) => rerender ( ) ) ;
97
107
}
108
+
109
+ if ( difficultyDropdownInstance ) {
110
+ difficultyDropdownInstance . setDifficulty ( allDifficulties ) ;
111
+ } else {
112
+ difficultyDropdownInstance = new window . DifficultyDropdown ( difficultyDropdownContainer , allDifficulties , ( ) => rerender ( ) ) ;
113
+ }
114
+
98
115
// Initial render
99
116
rerender ( ) ;
100
117
// Event listeners
0 commit comments