Skip to content

Commit 84187d1

Browse files
[icons] Try sync index addition
1 parent 64deec5 commit 84187d1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

docs/data/material/components/material-icons/SearchIcons.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,29 +518,31 @@ const searchIndex = new FlexSearchIndex({
518518
tokenize: 'full',
519519
});
520520

521+
const nameCleanRegex = /(Outlined|TwoTone|Rounded|Sharp)$/;
522+
521523
const allIconsMap = {};
522524
const allIcons = Object.keys(mui)
523525
.sort()
524526
.map((importName) => {
525527
let theme;
526-
if (importName.includes('Outlined')) {
528+
if (importName.endsWith('Outlined')) {
527529
theme = 'Outlined';
528-
} else if (importName.includes('TwoTone')) {
530+
} else if (importName.endsWith('TwoTone')) {
529531
theme = 'Two tone';
530-
} else if (importName.includes('Rounded')) {
532+
} else if (importName.endsWith('Rounded')) {
531533
theme = 'Rounded';
532-
} else if (importName.includes('Sharp')) {
534+
} else if (importName.endsWith('Sharp')) {
533535
theme = 'Sharp';
534536
} else {
535537
theme = 'Filled';
536538
}
537539

538-
const name = importName.replace(/(Outlined|TwoTone|Rounded|Sharp)$/, '');
540+
const name = importName.replace(nameCleanRegex, '');
539541
let searchable = name;
540542
if (synonyms[searchable]) {
541543
searchable += ` ${synonyms[searchable]}`;
542544
}
543-
searchIndex.addAsync(importName, searchable);
545+
searchIndex.add(importName, searchable);
544546

545547
const icon = {
546548
importName,
@@ -582,10 +584,14 @@ export default function SearchIcons() {
582584
}, [setSelectedIcon]);
583585

584586
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);
589595
}, [query, theme]);
590596

591597
const deferredIcons = React.useDeferredValue(icons);

0 commit comments

Comments
 (0)