move to new file

This commit is contained in:
Sara Vieira
2018-11-24 19:53:50 +01:00
parent 535484aa9c
commit b89f2ef7b5
2 changed files with 16 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ import { Pulsate } from '../../components/loading'
import { Subtitle, Flex, Anchor } from './elements'
import { fixNameB } from '../../utils/fixName'
import { search } from '../../utils/algolia'
import getCountryPerCity from '../../utils/getFlag'
class Search extends Component {
state = {
@@ -42,17 +43,11 @@ class Search extends Component {
}
getFlag = ({ name = '', objectID }) => {
fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${name}&key=AIzaSyDMpDkPdvwEG9mxQ3sA6vaKrq64V7trj_4`
)
.then(data => data.json())
.then(({ results }) => {
const address = results[0].address_components
const country = address.find(a => a.types.includes('country'))
this.setState({
[objectID]: country.short_name,
})
getCountryPerCity(name).then(({ short_name }) =>
this.setState({
[objectID]: short_name,
})
)
}
componentDidMount() {

11
src/utils/getFlag.js Normal file
View File

@@ -0,0 +1,11 @@
export default name =>
fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${name}&key=AIzaSyDMpDkPdvwEG9mxQ3sA6vaKrq64V7trj_4`
)
.then(data => data.json())
.then(({ results }) => {
const address = results[0].address_components
const country = address.find(a => a.types.includes('country'))
return country
})