File tree Expand file tree Collapse file tree 4 files changed +34
-6
lines changed
Expand file tree Collapse file tree 4 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ class App extends React.Component {
7474 < div >
7575 < header >
7676 < Link to = "/" > Adopt Me!</ Link >
77+ < Link to = "/search-params" >
78+ < span aria-label = "search" role = "img" >
79+ 🔍
80+ </ span >
81+ </ Link >
7782 </ header >
7883 < Provider value = { this . state } >
7984 < Router >
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from "react";
22import pf from "petfinder-client" ;
33import Pet from "./Pet" ;
44import SearchBox from "./SearchBox" ;
5+ import { Consumer } from "./SearchContext" ;
56
67const petfinder = pf ( {
78 key : process . env . API_KEY ,
@@ -17,8 +18,16 @@ class Results extends React.Component {
1718 } ;
1819 }
1920 componentDidMount ( ) {
21+ this . search ( ) ;
22+ }
23+ search = ( ) => {
2024 petfinder . pet
21- . find ( { location : "Seattle, WA" , output : "full" } )
25+ . find ( {
26+ location : this . props . searchParams . location ,
27+ animal : this . props . searchParams . animal ,
28+ breed : this . props . searchParams . breed ,
29+ output : "full"
30+ } )
2231 . then ( data => {
2332 let pets ;
2433 if ( data . petfinder . pets && data . petfinder . pets . pet ) {
@@ -34,11 +43,11 @@ class Results extends React.Component {
3443 pets : pets
3544 } ) ;
3645 } ) ;
37- }
46+ } ;
3847 render ( ) {
3948 return (
4049 < div className = "search" >
41- < SearchBox />
50+ < SearchBox search = { this . search } />
4251 { this . state . pets . map ( pet => {
4352 let breed ;
4453 if ( Array . isArray ( pet . breeds . breed ) ) {
@@ -63,4 +72,10 @@ class Results extends React.Component {
6372 }
6473}
6574
66- export default Results ;
75+ export default function ResultsWithContext ( props ) {
76+ return (
77+ < Consumer >
78+ { context => < Results { ...props } searchParams = { context } /> }
79+ </ Consumer >
80+ ) ;
81+ }
Original file line number Diff line number Diff line change @@ -3,12 +3,16 @@ import { ANIMALS } from "petfinder-client";
33import { Consumer } from "./SearchContext" ;
44
55class Search extends React . Component {
6+ handleFormSubmit = event => {
7+ event . preventDefault ( ) ;
8+ this . props . search ( ) ;
9+ } ;
610 render ( ) {
711 return (
812 < Consumer >
913 { context => (
1014 < div className = "search-params" >
11- < form >
15+ < form onSubmit = { this . handleFormSubmit } >
1216 < label htmlFor = "location" >
1317 Location
1418 < input
Original file line number Diff line number Diff line change 11import React from "react" ;
2+ import { navigate } from "@reach/router" ;
23import SearchBox from "./SearchBox" ;
34
45class Search extends React . Component {
6+ search ( ) {
7+ navigate ( "/" ) ;
8+ }
59 render ( ) {
610 return (
711 < div className = "search-route" >
8- < SearchBox />
12+ < SearchBox search = { this . search } />
913 </ div >
1014 ) ;
1115 }
You can’t perform that action at this time.
0 commit comments