Created
June 29, 2017 20:23
-
-
Save xavxyz/fc0287301e946ec71b814facd3efe3ee to your computer and use it in GitHub Desktop.
Exercise 13 @ Ticketmaster
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 { StyleSheet } from 'react-native'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
import Autocomplete from 'react-native-autocomplete-select'; | |
import { colors } from '../../lib/theme'; | |
import { input as inputActions } from '../../store/actions'; | |
const Input = ({ | |
inputValue, | |
suggestions = [ | |
{ description: 'Montpellier' }, | |
{ description: 'Los Angeles' }, | |
], | |
editInput, | |
resetInput, | |
}) => ( | |
<Autocomplete | |
suggestions={suggestions || []} | |
suggestionObjectTextProperty="description" | |
style={styles.autocomplete} | |
inputStyle={styles.input} | |
onChangeText={editInput} | |
onSelect={resetInput} | |
value={inputValue} | |
/> | |
); | |
const styles = StyleSheet.create({ | |
autocomplete: { | |
margin: 10, | |
alignSelf: 'stretch', | |
}, | |
input: { | |
padding: 10, | |
margin: 10, | |
height: 40, | |
color: colors.darkBlue, | |
borderWidth: 1, | |
borderColor: colors.darkBlue, | |
borderRadius: 2, | |
}, | |
}); | |
const mapStateToProps = state => ({ inputValue: state.input }); | |
const mapDispatchToProps = dispatch => | |
bindActionCreators(inputActions, dispatch); | |
// import the needed dependencies | |
const withData = graphql( | |
gql` | |
# use the query from GraphiQL | |
`, | |
{ | |
options: ({ inputValue }) => ({ | |
variables: { place: inputValue }, | |
}), | |
// use the props function as in App.js to give the component 'suggestions' | |
}, | |
); | |
export default connect(mapStateToProps, mapDispatchToProps)(Input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment