@@ -75,9 +75,10 @@ function applyAdvancedSearchPageHandlers() {
7575 const serverId = $ ( this ) . closest ( 'li' ) . data ( 'serverId' ) ;
7676 const specialFolders = [ ] ;
7777 [ 'archive' , 'draft' , 'junk' , 'sent' , 'trash' ] . forEach ( folderType => {
78- const folderName = hm_special_folders ( ) [ serverId ] [ folderType ] ;
79- if ( folderName ) {
80- specialFolders . push ( folderName ) ;
78+ const folders = hm_special_folders ( ) ?. [ serverId ] ;
79+ const folder = folders ?. find ( f => f . type === folderType ) ;
80+ if ( folder ) {
81+ specialFolders . push ( folder ) ;
8182 }
8283 } ) ;
8384
@@ -92,13 +93,13 @@ function applyAdvancedSearchPageHandlers() {
9293 modal . setContent ( `
9394 <div class="d-flex gap-3 flex-wrap">
9495 <div class="form-check form-switch">
95- <input class="form-check-input" type="checkbox" id="all">
96- <label class="form-check-label" for="all">All Folders</label>
96+ <input class="form-check-input" type="checkbox" id="all-special-folders ">
97+ <label class="form-check-label" for="all-special-folders ">All Folders</label>
9798 </div>
9899 ${ specialFolders . map ( folder => `
99100 <div class="form-check form-switch">
100- <input class="form-check-input special_folder_checkbox" type="checkbox" data-folder- id="${ folder } " ${ isFolderSelected ( folder ) ? 'checked' : '' } >
101- <label class="form-check-label" for="${ folder } ">${ folder } </label>
101+ <input class="form-check-input special_folder_checkbox" type="checkbox" id="${ folder . id } " ${ isFolderSelected ( folder . label ) ? 'checked' : '' } >
102+ <label class="form-check-label" for="${ folder . id } ">${ folder . label } </label>
102103 </div>
103104 ` ) . join ( '' ) }
104105 </div>
@@ -107,28 +108,28 @@ function applyAdvancedSearchPageHandlers() {
107108 modal . addFooterBtn ( 'Pick' , 'btn-primary' , function ( ) {
108109 const selectedFolders = [ ] ;
109110 $ ( '.special_folder_checkbox:checked' ) . each ( function ( ) {
110- selectedFolders . push ( $ ( this ) . data ( 'folder- id') ) ;
111+ selectedFolders . push ( specialFolders . find ( folder => folder . id === $ ( this ) . attr ( ' id') ) ) ;
111112 } ) ;
112113 selectedFolders . forEach ( folder => {
113- add_source_to_list ( accountId + folder , getFolderLabel ( folder ) , true ) ;
114+ add_source_to_list ( accountId + folder . id , getFolderLabel ( folder . label ) , true ) ;
114115 } ) ;
115116 modal . hide ( ) ;
116117 } ) ;
117118
118119 modal . open ( ) ;
119120
120- $ ( '#all' ) . on ( 'change' , function ( ) {
121+ $ ( '#all-special-folders ' ) . on ( 'change' , function ( ) {
121122 const checked = $ ( this ) . is ( ':checked' ) ;
122123 $ ( '.special_folder_checkbox' ) . prop ( 'checked' , checked ) ;
123124 } ) ;
124125
125126 $ ( '.special_folder_checkbox' ) . on ( 'change' , function ( ) {
126127 const allChecked = $ ( '.special_folder_checkbox' ) . length === $ ( '.special_folder_checkbox:checked' ) . length ;
127- $ ( '#all' ) . prop ( 'checked' , allChecked ) ;
128+ $ ( '#all-special-folders ' ) . prop ( 'checked' , allChecked ) ;
128129 } ) ;
129130
130- if ( specialFolders . every ( folder => isFolderSelected ( folder ) ) ) {
131- $ ( '#all' ) . prop ( 'checked' , true ) ;
131+ if ( specialFolders . every ( folder => isFolderSelected ( folder . label ) ) ) {
132+ $ ( '#all-special-folders ' ) . prop ( 'checked' , true ) ;
132133 }
133134 } ) ;
134135
0 commit comments