@@ -92,6 +92,19 @@ const GeneralSettings = ( {
9292 ) ;
9393 } , [ searchQuery , settingItems ] ) ;
9494
95+ // Create a Set of visible setting IDs for efficient lookups
96+ const visibleSettingIds = useMemo ( ( ) => {
97+ return new Set ( filteredSettings . map ( item => item . id ) ) ;
98+ } , [ filteredSettings ] ) ;
99+
100+ // Helper function to get highlight style for a setting
101+ const getHighlightStyle = ( settingId ) => {
102+ const setting = filteredSettings . find ( s => s . id === settingId ) ;
103+ return {
104+ backgroundColor : searchQuery && setting && matchesSearch ( setting . label ) ? '#fef3c7' : 'transparent'
105+ } ;
106+ } ;
107+
95108 return (
96109 < section >
97110 < div className = "shadow sm:rounded-md" >
@@ -110,10 +123,8 @@ const GeneralSettings = ( {
110123 </ div >
111124 ) }
112125 < div className = "pt-6 pb-20 px-8 grid grid-cols-4 gap-5" >
113- { filteredSettings . find ( s => s . id === 'docs_home' ) && (
114- < div className = "col-span-4"
115- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'docs_home' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
116- >
126+ { visibleSettingIds . has ( 'docs_home' ) && (
127+ < div className = "col-span-4" style = { getHighlightStyle ( 'docs_home' ) } >
117128 < div className = "settings-content flex items-center justify-between" >
118129 < div className = "settings-field-heading md:min-w-[300px] flex items-center space-x-2 flex-1" >
119130 < label
@@ -155,10 +166,8 @@ const GeneralSettings = ( {
155166 </ div >
156167 ) }
157168
158- { filteredSettings . find ( s => s . id === 'email' ) && (
159- < div className = "col-span-4"
160- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'email' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
161- >
169+ { visibleSettingIds . has ( 'email' ) && (
170+ < div className = "col-span-4" style = { getHighlightStyle ( 'email' ) } >
162171 < div className = "settings-content flex items-center justify-between" >
163172 < div className = "settings-heading md:min-w-[300px] flex items-center space-x-2 flex-1" >
164173 < label
@@ -205,11 +214,9 @@ const GeneralSettings = ( {
205214 </ div >
206215 ) }
207216
208- { filteredSettings . find ( s => s . id === 'email_to' ) && ( generalSettingsData ?. email === 'on' ||
217+ { visibleSettingIds . has ( 'email_to' ) && ( generalSettingsData ?. email === 'on' ||
209218 ! Boolean ( generalSettingsData ?. email ) ) && (
210- < div className = "col-span-4"
211- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'email_to' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
212- >
219+ < div className = "col-span-4" style = { getHighlightStyle ( 'email_to' ) } >
213220 < div className = "settings-content flex items-center justify-between" >
214221 < div className = "settings-field-heading md:min-w-[300px] flex items-center space-x-2 flex-1" >
215222 < label
@@ -263,10 +270,8 @@ const GeneralSettings = ( {
263270 </ div >
264271 ) }
265272
266- { filteredSettings . find ( s => s . id === 'enable_search' ) && (
267- < div className = "col-span-4"
268- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'enable_search' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
269- >
273+ { visibleSettingIds . has ( 'enable_search' ) && (
274+ < div className = "col-span-4" style = { getHighlightStyle ( 'enable_search' ) } >
270275 < div className = "settings-content flex items-center justify-between" >
271276 < div className = "settings-heading md:min-w-[300px] space-x-2 items-center flex flex-1" >
272277 < label
@@ -313,10 +318,8 @@ const GeneralSettings = ( {
313318 </ div >
314319 ) }
315320
316- { filteredSettings . find ( s => s . id === 'helpful' ) && (
317- < div className = "col-span-4"
318- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'helpful' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
319- >
321+ { visibleSettingIds . has ( 'helpful' ) && (
322+ < div className = "col-span-4" style = { getHighlightStyle ( 'helpful' ) } >
320323 < div className = "settings-content flex items-center justify-between" >
321324 < div className = "settings-heading md:min-w-[300px] space-x-2 items-center flex flex-1" >
322325 < label
@@ -363,10 +366,8 @@ const GeneralSettings = ( {
363366 </ div >
364367 ) }
365368
366- { filteredSettings . find ( s => s . id === 'comments' ) && (
367- < div className = "col-span-4"
368- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'comments' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
369- >
369+ { visibleSettingIds . has ( 'comments' ) && (
370+ < div className = "col-span-4" style = { getHighlightStyle ( 'comments' ) } >
370371 < div className = "settings-content flex items-center justify-between mt-1" >
371372 < div className = "settings-heading md:min-w-[300px] space-x-2 items-center flex flex-1" >
372373 < label
@@ -413,10 +414,8 @@ const GeneralSettings = ( {
413414 </ div >
414415 ) }
415416
416- { filteredSettings . find ( s => s . id === 'print' ) && (
417- < div className = "col-span-4"
418- style = { { backgroundColor : searchQuery && matchesSearch ( filteredSettings . find ( s => s . id === 'print' ) ?. label || '' ) ? '#fef3c7' : 'transparent' } }
419- >
417+ { visibleSettingIds . has ( 'print' ) && (
418+ < div className = "col-span-4" style = { getHighlightStyle ( 'print' ) } >
420419 < div className = "settings-content flex items-center justify-between" >
421420 < div className = "settings-heading md:min-w-[300px] space-x-2 items-center flex flex-1" >
422421 < label
0 commit comments