File tree Expand file tree Collapse file tree 2 files changed +32
-23
lines changed
Expand file tree Collapse file tree 2 files changed +32
-23
lines changed Original file line number Diff line number Diff line change 11import gql from 'graphql-tag' ;
22
33export const EXAMPLE = gql `
4- {
5- search(term: "burrito" , location: "san francisco" ) {
4+ query Search($term: String!,$location:String!) {
5+ search(term: $term , location: $location ) {
66 total
77 business {
88 name
Original file line number Diff line number Diff line change @@ -5,30 +5,39 @@ import { Query } from "react-apollo";
55
66
77export default class Home extends Component {
8+ getYelp ( { term, location } ) {
9+ return (
10+ < Query query = { EXAMPLE } variables = { { term, location } } >
11+ { ( { loading, data : { search } , error } ) => {
12+ if ( loading ) {
13+ return < Text > Loading...</ Text >
14+ }
15+ if ( search ) {
16+ const result = search . business . map ( ( i , index ) => {
17+ return (
18+ < View key = { index } >
19+ < Text > { index + 1 + ". " + i . name } </ Text >
20+ < Text > Rating: { i . rating } - Review: { i . review_count } </ Text >
21+ < Text > { i . location . address1 } </ Text >
22+ </ View > )
23+ } )
24+ return result ;
25+ }
26+ if ( error )
27+ return < Text > { error . message } </ Text >
28+
29+ return (
30+ < Text > No result</ Text >
31+ ) ;
32+ } }
33+ </ Query >
34+ )
35+ }
836 render ( ) {
37+
938 return (
1039 < ScrollView >
11- < Query query = { EXAMPLE } >
12- { ( { client, loading, data : { search } } ) => {
13- if ( loading ) {
14- return < Text > Loading...</ Text >
15- }
16- if ( search ) {
17- const result = search . business . map ( ( i , index ) => {
18- return (
19- < View key = { index } >
20- < Text > { index + 1 + ". " + i . name } </ Text >
21- < Text > Rating: { i . rating } - Review: { i . review_count } </ Text >
22- < Text > { i . location . address1 } </ Text >
23- </ View > )
24- } )
25- return result ;
26- }
27- return (
28- < Text > No result</ Text >
29- ) ;
30- } }
31- </ Query >
40+ { this . getYelp ( { term : "burrito" , location : "san francis" } ) }
3241 </ ScrollView >
3342 )
3443 }
You can’t perform that action at this time.
0 commit comments