@@ -518,29 +518,31 @@ const searchIndex = new FlexSearchIndex({
518
518
tokenize : 'full' ,
519
519
} ) ;
520
520
521
+ const nameCleanRegex = / ( O u t l i n e d | T w o T o n e | R o u n d e d | S h a r p ) $ / ;
522
+
521
523
const allIconsMap = { } ;
522
524
const allIcons = Object . keys ( mui )
523
525
. sort ( )
524
526
. map ( ( importName ) => {
525
527
let theme ;
526
- if ( importName . includes ( 'Outlined' ) ) {
528
+ if ( importName . endsWith ( 'Outlined' ) ) {
527
529
theme = 'Outlined' ;
528
- } else if ( importName . includes ( 'TwoTone' ) ) {
530
+ } else if ( importName . endsWith ( 'TwoTone' ) ) {
529
531
theme = 'Two tone' ;
530
- } else if ( importName . includes ( 'Rounded' ) ) {
532
+ } else if ( importName . endsWith ( 'Rounded' ) ) {
531
533
theme = 'Rounded' ;
532
- } else if ( importName . includes ( 'Sharp' ) ) {
534
+ } else if ( importName . endsWith ( 'Sharp' ) ) {
533
535
theme = 'Sharp' ;
534
536
} else {
535
537
theme = 'Filled' ;
536
538
}
537
539
538
- const name = importName . replace ( / ( O u t l i n e d | T w o T o n e | R o u n d e d | S h a r p ) $ / , '' ) ;
540
+ const name = importName . replace ( nameCleanRegex , '' ) ;
539
541
let searchable = name ;
540
542
if ( synonyms [ searchable ] ) {
541
543
searchable += ` ${ synonyms [ searchable ] } ` ;
542
544
}
543
- searchIndex . addAsync ( importName , searchable ) ;
545
+ searchIndex . add ( importName , searchable ) ;
544
546
545
547
const icon = {
546
548
importName,
@@ -582,10 +584,14 @@ export default function SearchIcons() {
582
584
} , [ setSelectedIcon ] ) ;
583
585
584
586
const icons = React . useMemo ( ( ) => {
585
- const keys = query === '' ? null : searchIndex . search ( query , { limit : 3000 } ) ;
586
- return ( keys === null ? allIcons : keys . map ( ( key ) => allIconsMap [ key ] ) ) . filter (
587
- ( icon ) => theme === icon . theme ,
588
- ) ;
587
+ if ( query === '' ) {
588
+ return allIcons ;
589
+ }
590
+
591
+ return searchIndex
592
+ . search ( query , { limit : 3000 } )
593
+ . map ( ( key ) => allIconsMap [ key ] )
594
+ . filter ( ( icon ) => icon . theme === theme ) ;
589
595
} , [ query , theme ] ) ;
590
596
591
597
const deferredIcons = React . useDeferredValue ( icons ) ;
0 commit comments