Skip to content

Commit 7f3ad0a

Browse files
author
Gabriel Gavilan
committed
Remove heavy setResults callback, and use css magic instead.
1 parent 73062fc commit 7f3ad0a

3 files changed

Lines changed: 7 additions & 18 deletions

File tree

packages/preview/src/components/pages/search/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import SearchIconSet from "./search-iconset";
77
export default function SearchPageComponent() {
88
const allIcons = ALL_ICONS;
99

10-
const { query, results, setResults } = React.useContext(Context);
11-
12-
const getTotal = (results: object) => {
13-
return results ?
14-
Object.values(results).reduce((p: number, c: number) => p + c, 0) :
15-
0
16-
}
10+
const { query } = React.useContext(Context);
1711

1812
if (query.length > 2) {
1913
const hightlightPattern = new RegExp(`(${query})`, "i");
@@ -28,12 +22,11 @@ export default function SearchPageComponent() {
2822
key={icon.id}
2923
icon={icon}
3024
query={query}
31-
setResults={setResults}
3225
highlightPattern={hightlightPattern}
3326
/>
3427
))}
3528
</div>
36-
{getTotal(results) === 0 && <h3>No icons found</h3>}
29+
<h3 className="no-results"/>
3730
</>
3831
);
3932
}

packages/preview/src/components/pages/search/search-iconset.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getIcons } from "@utils/getIcons";
55

66
import SearchPageIconLoading from "./loading";
77

8-
export default function SearchIconSet({ icon, query, setResults, highlightPattern }) {
8+
export default function SearchIconSet({ icon, query, highlightPattern }) {
99
const IconSet = loadable.lib(() => getIcons(icon.id));
1010

1111
return (
@@ -23,14 +23,6 @@ export default function SearchIconSet({ icon, query, setResults, highlightPatter
2323
highlightPattern={highlightPattern}
2424
/>
2525
))}
26-
{setResults(prevResults => {
27-
return prevResults.hasOwnProperty(icon.id) ?
28-
prevResults :
29-
{
30-
...prevResults,
31-
[icon.id]: found.length
32-
}
33-
})}
3426
</>
3527
)
3628
}}

packages/preview/src/styles/_components.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,7 @@ a {
237237
display: none;
238238
}
239239
}
240+
241+
.icons:empty + .no-results:after {
242+
content: "No icons found";
243+
}

0 commit comments

Comments
 (0)