@@ -34,6 +34,13 @@ class DifficultyDropdown {
3434 this . list . className = 'difficulty-dropdown-list'
3535 this . list . style . display = 'none'
3636
37+ this . searchInput = document . createElement ( 'input' ) ;
38+ this . searchInput . type = 'text' ;
39+ this . searchInput . className = 'difficulty-dropdown-search' ;
40+ this . searchInput . placeholder = 'Search Difficulties...' ;
41+ this . searchInput . addEventListener ( 'input' , ( ) => this . filterDifficulties ( ) ) ;
42+ this . list . appendChild ( this . searchInput ) ;
43+
3744 this . optionsContainer = document . createElement ( 'div' ) ;
3845 this . optionsContainer . className = 'difficulty-dropdown-options' ;
3946 this . list . appendChild ( this . optionsContainer ) ;
@@ -48,14 +55,28 @@ class DifficultyDropdown {
4855 }
4956
5057 renderOptions ( ) {
51-
58+ this . optionsContainer . innerHTML = '' ;
59+ this . filteredDifficulties . forEach ( difficulty => {
60+ const opt = document . createElement ( 'div' ) ;
61+ opt . className = 'difficulty-dropdown-option' ;
62+ opt . textContent = difficulty === 'all' ? 'All Difficulties' : difficulty ;
63+ if ( difficulty === this . selectedDifficulty ) opt . classList . add ( 'selected' ) ;
64+ opt . addEventListener ( 'click' , ( ) => this . selectDifficulty ( difficulty ) ) ;
65+ this . optionsContainer . appendChild ( opt ) ;
66+ } ) ;
5267 }
5368
5469 filterDifficulties ( ) {
55- // TODO: Finish function
70+ const val = this . searchInput . value . toLowerCase ( ) ;
71+ this . filteredDifficulties = [ 'all' , ...this . difficulties
72+ . filter ( difficulty => difficulty
73+ . toLowerCase ( )
74+ . includes ( val )
75+ ) ] ;
76+ this . renderOptions ( ) ;
5677 }
5778
58- selectDifficulty ( tag ) {
79+ selectDifficulty ( difficulty ) {
5980 // TODO: Finish function
6081 }
6182
0 commit comments