Skip to content

Commit

Permalink
add check for user location on alarm click
Browse files Browse the repository at this point in the history
  • Loading branch information
cadrianxyz committed Mar 21, 2020
1 parent efde26d commit c85afe7
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions screens/UsingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,37 @@ const MAXIMUM_DISTANCE = 1000000000 // meters

const UsingScreen = (props) => {

const { time, userId, token } = props;
const { location, time, userId, token } = props;
const { timeRemaining } = time

const startAlarm = () => {
const distance = computeDistance(fredVictorCoordinates, props.location.coords)
if( distance > MAXIMUM_DISTANCE ) Alert.alert("Cannot start alarm", "There are no responders within your area", [
{ text: 'OK' }
], { cancelable: false })
else {
Actions.alarm();
// Check if location has been set
console.log({location})
if( location === null
|| location.coords === null
|| (location.coords.lat !== 0 && location.coords.lng !== 0)
) {
Alert.alert("Cannot start alarm", "Your location is not set. Please set your location in the 'locations' page' and enable location services on your device.", [
{ text: 'Set my location now', onPress: () => {
Actions.location()
} },
{ text: 'Cancel', onPress: () => {} }
], { cancelable: false })
return null
}

props.makeAlarmLog(userId, timeRemaining, token);
// Check for responders in the area (for beta-testing, compare to the coordinates of the Fred Victor Building)
const distance = computeDistance(fredVictorCoordinates, location.coords)
if( distance > MAXIMUM_DISTANCE ) {
Alert.alert("Cannot start alarm", "There are no responders within your area", [
{ text: 'OK' }
], { cancelable: false })
return null
}

Actions.alarm();

props.makeAlarmLog(userId, timeRemaining, token);
}

return (
Expand Down

0 comments on commit c85afe7

Please sign in to comment.