1
+ import gql from "graphql-tag" ;
1
2
import { FC , useState } from "react" ;
2
3
import { Menu , Transition } from "@headlessui/react" ;
3
4
import classNames from "classnames" ;
4
5
import { Link } from "react-router-dom" ;
6
+ import { useQuery } from "@apollo/client" ;
7
+ import { Search } from "./__generated__/Search" ;
8
+ import { SearchResults } from "../components/SearchResults" ;
9
+
10
+ const SEARCH = gql `
11
+ query Search($term: String!) {
12
+ search(query: $term) {
13
+ documents {
14
+ edges {
15
+ node {
16
+ name
17
+ description
18
+ url
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+ ` ;
5
25
6
26
export const Home : FC = ( ) => {
7
27
const [ isOpen , setIsOpen ] = useState ( false ) ;
28
+ const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
29
+
30
+ const searchResults = useQuery < Search > ( SEARCH , {
31
+ variables : { term : searchTerm } ,
32
+ } ) ;
8
33
9
34
return (
10
35
< div style = { { minHeight : "712px" } } className = "overflow-y-auto" >
@@ -126,7 +151,7 @@ export const Home: FC = () => {
126
151
{ /* Search */ }
127
152
< div className = "flex-1 min-w-0 px-12 lg:hidden" >
128
153
< div className = "max-w-xs w-full mx-auto" >
129
- < label htmlFor = "search" className = "sr-only" >
154
+ < label htmlFor = "mobile- search" className = "sr-only" >
130
155
Search
131
156
</ label >
132
157
< div className = "relative text-white focus-within:text-gray-600" >
@@ -146,11 +171,13 @@ export const Home: FC = () => {
146
171
</ svg >
147
172
</ div >
148
173
< input
149
- id = "search"
150
- className = "block w-full bg-white bg-opacity-20 py-2 pl-10 pr-3 border border-transparent rounded-md leading-5 text-gray-900 placeholder-white focus:outline-none focus:bg-opacity-100 focus:border-transparent focus:placeholder-gray-500 focus:ring-0 sm:text-sm"
174
+ id = "mobile- search"
175
+ className = "block w-full bg-white bg-opacity-20 py-2 pl-10 pr-3 border border-transparent rounded-md leading-5 focus: text-gray-900 placeholder-white focus:outline-none focus:bg-opacity-100 focus:border-transparent focus:placeholder-gray-500 focus:ring-0 sm:text-sm"
151
176
placeholder = "Search"
152
177
type = "search"
153
178
name = "search"
179
+ value = { searchTerm }
180
+ onChange = { event => setSearchTerm ( event . target . value ) }
154
181
/>
155
182
</ div >
156
183
</ div >
@@ -272,10 +299,12 @@ export const Home: FC = () => {
272
299
</ div >
273
300
< input
274
301
id = "search"
275
- className = "block w-full bg-white bg-opacity-20 py-2 pl-10 pr-3 border border-transparent rounded-md leading-5 text-gray-900 placeholder-white focus:outline-none focus:bg-opacity-100 focus:border-transparent focus:placeholder-gray-500 focus:ring-0 sm:text-sm"
302
+ className = "block w-full bg-white bg-opacity-20 py-2 pl-10 pr-3 border border-transparent rounded-md leading-5 focus: text-gray-900 placeholder-white focus:outline-none focus:bg-opacity-100 focus:border-transparent focus:placeholder-gray-500 focus:ring-0 sm:text-sm"
276
303
placeholder = "Search"
277
304
type = "search"
278
305
name = "search"
306
+ value = { searchTerm }
307
+ onChange = { event => setSearchTerm ( event . target . value ) }
279
308
/>
280
309
</ div >
281
310
</ div >
@@ -440,29 +469,28 @@ export const Home: FC = () => {
440
469
{ /* Main 3 column grid */ }
441
470
< div className = "grid grid-cols-1 gap-4 items-start lg:grid-cols-3 lg:gap-8" >
442
471
{ /* Left column */ }
443
- < div className = "grid grid-cols-1 gap-4 lg:col-span-2" >
472
+ { /* <div className="grid grid-cols-1 gap-4 lg:col-span-2">
444
473
<section aria-labelledby="section-1-title">
445
474
<h2 className="sr-only" id="section-1-title">
446
475
Section title
447
476
</h2>
448
477
<div className="rounded-lg bg-white overflow-hidden shadow">
449
478
<div className="p-6">
450
- { /* <x-placeholder>
451
- <div className="h-96 border-4 border-dashed border-gray-200 rounded-lg"></div>
452
- </x-placeholder> */ }
479
+ <div className="h-96 border-4 border-dashed border-gray-200 rounded-lg"></div>
453
480
</div>
454
481
</div>
455
482
</section>
456
- </ div >
483
+ </div> */ }
457
484
458
485
{ /* Right column */ }
459
- < div className = "grid grid-cols-1 gap-4" >
486
+ < div className = "grid grid-cols-1 lg:col-span-3 gap-4" >
460
487
< section aria-labelledby = "section-2-title" >
461
488
< h2 className = "sr-only" id = "section-2-title" >
462
489
Section title
463
490
</ h2 >
464
491
< div className = "rounded-lg bg-white overflow-hidden shadow" >
465
- < div className = "p-6" >
492
+ < div className = "px-6 py-2" >
493
+ < SearchResults { ...searchResults } />
466
494
{ /* <x-placeholder>
467
495
<div className="h-96 border-4 border-dashed border-gray-200 rounded-lg"></div>
468
496
</x-placeholder> */ }
0 commit comments