-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import LunchSpotApp code from messy livecoded repository
- Loading branch information
Showing
23 changed files
with
354 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
rootProject.name = 'LunchSpotApp' | ||
include ':react-native-maps' | ||
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android') | ||
include ':react-native-photo-view' | ||
project(':react-native-photo-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-photo-view/android') | ||
include ':react-native-share' | ||
project(':react-native-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share/android') | ||
include ':react-native-linear-gradient' | ||
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android') | ||
include ':react-native-vector-icons' | ||
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') | ||
include ':react-native-maps' | ||
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android') | ||
|
||
include ':app' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import { Screen, Spinner, Examples } from '@shoutem/ui'; | ||
import { stringify as queryString } from 'query-string'; | ||
|
||
import styles from './styles'; | ||
import RecommendationsMap from './RecommendationsMap'; | ||
import { OverlayTopics, BottomTopics } from './Topics'; | ||
|
||
const CLIENT_ID = '4VMVDF0DJLP4DKSFNW210VFMEL1OJ3P5HAAQJGOC4YFYIOJ2'; | ||
const CLIENT_SECRET = 'ZXA5FEE4GJY4S525PBWUDM22R3FTNTOHKQ0FMJNV0GGBTYBU'; | ||
const FOURSQUARE_ENDPOINT = 'https://api.foursquare.com/v2/venues/explore'; | ||
const API_DEBOUNCE_TIME = 2000; | ||
|
||
class App extends Component { | ||
state = { | ||
mapRegion: null, | ||
gpsAccuracy: null, | ||
recommendations: [], | ||
lookingFor: null, | ||
headerLocation: null, | ||
last4sqCall: null | ||
} | ||
watchID = null | ||
|
||
componentWillMount() { | ||
this.watchID = navigator.geolocation.watchPosition((position) => { | ||
let region = { | ||
latitude: position.coords.latitude, | ||
longitude: position.coords.longitude, | ||
latitudeDelta: 0.00922*1.5, | ||
longitudeDelta: 0.00421*1.5 | ||
} | ||
|
||
this.onRegionChange(region, position.coords.accuracy); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
navigator.geolocation.clearWatch(this.watchID); | ||
} | ||
|
||
onRegionChange(region, gpsAccuracy) { | ||
this.fetchVenues(region); | ||
|
||
this.setState({ | ||
mapRegion: region, | ||
gpsAccuracy: gpsAccuracy || this.state.gpsAccuracy | ||
}); | ||
} | ||
|
||
fetchVenues(region, lookingFor) { | ||
if (!this.shouldFetchVenues(lookingFor)) return; | ||
|
||
const query = this.venuesQuery(region, lookingFor); | ||
|
||
fetch(`${FOURSQUARE_ENDPOINT}?${query}`) | ||
.then(fetch.throwErrors) | ||
.then(res => res.json()) | ||
.then(json => { | ||
if (json.response.groups) { | ||
this.setState({ | ||
recommendations: json.response.groups.reduce( | ||
(all, g) => all.concat(g ? g.items : []), [] | ||
), | ||
headerLocation: json.response.headerLocation, | ||
last4sqCall: new Date() | ||
}); | ||
} | ||
}) | ||
.catch(err => console.log(err)); | ||
} | ||
|
||
shouldFetchVenues(lookingFor) { | ||
return lookingFor != this.state.lookingFor | ||
|| this.state.last4sqCall === null | ||
|| new Date() - this.state.last4sqCall > API_DEBOUNCE_TIME; | ||
} | ||
|
||
venuesQuery({ latitude, longitude }, lookingFor) { | ||
return queryString({ | ||
client_id: CLIENT_ID, | ||
client_secret: CLIENT_SECRET, | ||
v: 20170305, | ||
ll: `${latitude}, ${longitude}`, | ||
llAcc: this.state.gpsAccuracy, | ||
section: lookingFor || this.state.lookingFor || 'food', | ||
limit: 10, | ||
openNow: 1, | ||
venuePhotos: 1 | ||
}); | ||
} | ||
|
||
onTopicSelect(lookingFor) { | ||
this.fetchVenues(this.state.mapRegion, lookingFor); | ||
|
||
this.setState({ | ||
lookingFor: lookingFor | ||
}); | ||
} | ||
|
||
render() { | ||
const { mapRegion, lookingFor } = this.state; | ||
|
||
if (mapRegion) { | ||
return ( | ||
<Screen> | ||
<RecommendationsMap {...this.state} onRegionChange={this.onRegionChange.bind(this)} /> | ||
|
||
{!lookingFor ? <OverlayTopics onTopicSelect={this.onTopicSelect.bind(this)} /> | ||
: <BottomTopics onTopicSelect={this.onTopicSelect.bind(this)} />} | ||
</Screen> | ||
); | ||
}else{ | ||
return ( | ||
<Screen style={styles.centered}> | ||
<Spinner styleName="large" /> | ||
</Screen> | ||
); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
export default App; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import MapView from 'react-native-maps'; | ||
import { Card, Image, View, Subtitle, Text, Caption } from '@shoutem/ui'; | ||
|
||
|
||
class Recommendation extends Component { | ||
get photo() { | ||
const photo = this.props.venue.photos.groups[0].items[0]; | ||
|
||
return `${photo.prefix}300x500${photo.suffix}`; | ||
} | ||
|
||
render() { | ||
const { venue, tips } = this.props; | ||
|
||
return ( | ||
<MapView.Marker coordinate={{latitude: venue.location.lat, | ||
longitude: venue.location.lng}}> | ||
|
||
<MapView.Callout> | ||
<Card> | ||
<Image styleName="medium-wide" | ||
source={{uri: this.photo}} /> | ||
<View styleName="content"> | ||
<Subtitle>{venue.name}</Subtitle> | ||
<Caption>{tips ? tips[0].text : ''}</Caption> | ||
</View> | ||
</Card> | ||
</MapView.Callout> | ||
</MapView.Marker> | ||
) | ||
} | ||
} | ||
|
||
export default Recommendation; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import React, { Component } from 'react'; | ||
|
||
import MapView from 'react-native-maps' | ||
import { Subtitle, Title } from '@shoutem/ui'; | ||
|
||
import styles from './styles'; | ||
import Recommendation from './Recommendation'; | ||
|
||
const RecommendationsMap = ({ mapRegion, gpsAccuracy, recommendations, lookingFor, | ||
headerLocation, onRegionChange }) => ( | ||
|
||
<MapView.Animated region={mapRegion} | ||
style={styles.fullscreen} | ||
onRegionChange={onRegionChange}> | ||
|
||
<Title styleName="h-center multiline" style={styles.mapHeader}> | ||
{lookingFor ? `${lookingFor} in` : ''} {headerLocation} | ||
</Title> | ||
|
||
<MapView.Circle center={mapRegion} | ||
radius={gpsAccuracy*1.5} | ||
strokeWidth={0.5} | ||
strokeColor="rgba(66, 180, 230, 1)" | ||
fillColor="rgba(66, 180, 230, 0.2)" | ||
/> | ||
|
||
<MapView.Circle center={mapRegion} | ||
radius={5} | ||
strokeWidth={0.5} | ||
strokeColor="rgba(66, 180, 230, 1)" | ||
fillColor="rgba(66, 180, 230, 1)" | ||
/> | ||
|
||
{recommendations.map(r => <Recommendation {...r} key={r.venue.id} />)} | ||
|
||
</MapView.Animated> | ||
); | ||
|
||
export default RecommendationsMap; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import React, { Component } from 'react'; | ||
import { View, Button, Text, Overlay, Heading } from '@shoutem/ui'; | ||
|
||
import styles from './styles'; | ||
|
||
const TOPICS = ['food', 'drinks', 'coffee', 'shops', 'sights', 'arts']; | ||
|
||
const OverlayTopics = ({ onTopicSelect }) => ( | ||
<Overlay styleName="fill-parent"> | ||
<Heading style={{marginBottom: 15}}>What do you feel like?</Heading> | ||
{TOPICS.map(topic => ( | ||
<Button onPress={() => onTopicSelect(topic)} key={topic} style={{marginBottom: 10}}> | ||
<Text>{topic}</Text> | ||
</Button> | ||
))} | ||
</Overlay> | ||
); | ||
|
||
const BottomTopics = ({ onTopicSelect }) => ( | ||
<View styleName="horizontal"> | ||
{TOPICS.map(topic => ( | ||
<Button onPress={() => onTopicSelect(topic)} key={topic} styleName="muted"> | ||
<Text>{topic}</Text> | ||
</Button> | ||
))} | ||
</View> | ||
); | ||
|
||
export { OverlayTopics, BottomTopics }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
import { StyleSheet } from 'react-native'; | ||
|
||
const styles = { | ||
fullscreen: { | ||
flex: 1, | ||
}, | ||
centered: { | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}, | ||
mapHeader: { | ||
backgroundColor: "rgba(255, 255, 255, .7)", | ||
paddingTop: 20 | ||
} | ||
}; | ||
|
||
export default styles; |
This file contains 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
Oops, something went wrong.