Created
August 18, 2019 13:31
-
-
Save elie222/23ce601ea43bd240ea7c1de85a76df90 to your computer and use it in GitHub Desktop.
Using GraphQL code generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Text, View, TouchableOpacity, ImageBackground, ScrollView } from 'react-native' | |
import gql from 'graphql-tag' | |
import { FlatGrid } from 'react-native-super-grid' | |
import { useItemsQuery } from '../../generated/graphql' | |
export const ITEMS_QUERY = gql` | |
query Items($communityId: String!) { | |
items(communityId: $communityId) { | |
_id | |
name | |
price | |
userId | |
communityId | |
imageUrl | |
locationLng | |
locationLat | |
} | |
} | |
` | |
const Items = (props: { navigation: any }) => { | |
const communityId = props.navigation.getParam('communityId') | |
const communityName = props.navigation.getParam('communityName') | |
const { loading, error, data } = useItemsQuery({ | |
variables: { | |
communityId, | |
}, | |
}) | |
if (!data) return null | |
return ( | |
<ScrollView> | |
<Text>{communityName}</Text> | |
<FlatGrid | |
items={data.items} | |
renderItem={({ item }) => ( | |
<TouchableOpacity | |
onPress={() => { | |
props.navigation.navigate('Item', { | |
item, | |
}) | |
}} | |
> | |
<ImageBackground | |
imageStyle={{ borderRadius: 10 }} | |
source={{ uri: item.imageUrl }} | |
> | |
<Text>{item.name}</Text> | |
</ImageBackground> | |
</TouchableOpacity> | |
)} | |
/> | |
</ScrollView> | |
) | |
} | |
export default Items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment