1
1
import React , { FC , Fragment } from 'react'
2
- import { prop } from 'ramda'
3
2
import { useQuery } from 'react-apollo'
4
3
5
4
import RightArrow from './components/icons/RightArrow'
@@ -12,31 +11,35 @@ interface Props {
12
11
}
13
12
}
14
13
14
+ interface SearchQueryResult {
15
+ searchEngine : SearchResult [ ]
16
+ }
17
+
15
18
interface SearchResult {
16
19
title : string
17
20
snippet : string
18
21
link : string
19
22
}
20
23
21
- const isNotLastResult = ( results : [ SearchResult ] , index : number ) =>
24
+ const isNotLastResult = ( results : SearchResult [ ] , index : number ) =>
22
25
index !== results . length - 1
23
26
24
27
const isFirstResult = ( index : number ) => index === 0
25
28
26
29
const Search : FC < Props > = ( { query } ) => {
27
30
const queryString = query . q || ''
28
31
29
- const { data, loading } = useQuery ( searchEngine , {
32
+ const { data, loading } = useQuery < SearchQueryResult > ( searchEngine , {
30
33
variables : { searchQuery : queryString } ,
31
34
} )
32
35
33
- const results : [ SearchResult ] = prop ( ' searchEngine' , data ) || [ ]
36
+ const results = data ?. searchEngine ?? [ ]
34
37
35
38
return (
36
39
< Fragment >
37
40
{ ! loading ? (
38
41
queryString && (
39
- < div className = { ` w-100 flex flex-column` } >
42
+ < div className = " w-100 flex flex-column" >
40
43
< h1 className = "t-heading-3" >
41
44
{ results . length > 0
42
45
? `Results for "${ queryString } "`
0 commit comments