Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 4ce58ea

Browse files
committed
give search results functionality
1 parent faaa265 commit 4ce58ea

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/views/SearchResults.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ function SearchResultsView () {
1313
const [appState, dispatch] = useStateValue()
1414

1515
const query = useQuery().get('q')
16-
const queryOk = query.length >= 2
16+
const queryOk = query.length >= 1
1717

1818
if (!queryOk) return <Redirect to='/' />
1919

20+
let programs = appState.programs
21+
if (query) {
22+
programs = programs.filter(({ payload: { value: { name, type, address } } }) =>
23+
name.includes(query) || type.includes(query) || address.toString().includes(query)
24+
)
25+
}
26+
2027
return (
2128
<Pane display='flex' justifyContent='center'>
2229
<Pane
@@ -28,10 +35,10 @@ function SearchResultsView () {
2835
>
2936
<Pane borderBottom='default'>
3037
<Heading size={600} marginBottom={majorScale(1)}>
31-
{appState.programs.length} programs found
38+
{programs.length} programs found
3239
</Heading>
3340
</Pane>
34-
{appState.programs !== loadingState ? <ProgramList programs={appState.programs} /> : <Spinner marginX='auto' marginY={120} />}
41+
{programs !== loadingState ? <ProgramList programs={programs} /> : <Spinner marginX='auto' marginY={120} />}
3542
</Pane>
3643
</Pane>
3744
)

0 commit comments

Comments
 (0)