Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
fix: fetch user location immediately (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Abraham <[email protected]>
  • Loading branch information
shottah and shottah authored Apr 21, 2023
1 parent 82ad9b7 commit 1e48962
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 189 deletions.
258 changes: 129 additions & 129 deletions ios/celo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
ReferencedContainer = "container:celo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "San Francisco, CA, USA"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
ReferencedContainer = "container:celo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "San Francisco, CA, USA"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
ReferencedContainer = "container:celo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "San Francisco, CA, USA"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
ReferencedContainer = "container:celo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "San Francisco, CA, USA"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
14 changes: 10 additions & 4 deletions scripts/run_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ set -euo pipefail
# -e (Optional): Name of the env to run
# -r (Optional): Use release build (by default uses debug). Note: on Android the release keystore needs to be present and the password in the env variable for this to work.
# -s (Optional): Name of the simulator to run (iOS only)
# -d (Optional): Name of the device to run (iOS only)

PLATFORM=""
ENV_NAME="alfajoresdev"
RELEASE=false
SIMULATOR=""
DEVICE=""

while getopts 'p:e:s:r' flag; do
while getopts 'p:e:rs:d:' flag; do
case "${flag}" in
p) PLATFORM="$OPTARG" ;;
e) ENV_NAME="$OPTARG" ;;
s) SIMULATOR="$OPTARG" ;;
p) PLATFORM="${OPTARG}" ;;
e) ENV_NAME="${OPTARG}" ;;
r) RELEASE=true ;;
s) SIMULATOR="${OPTARG}" ;;
d) DEVICE="${OPTARG}" ;;
*) error "Unexpected option ${flag}" ;;
esac
done
Expand Down Expand Up @@ -121,6 +124,9 @@ elif [ "$PLATFORM" = "ios" ]; then
if [ -n "$SIMULATOR" ]; then
simulator_param="--simulator=$SIMULATOR"
fi
if [ -n "$DEVICE" ]; then
simulator_param="--device=$DEVICE"
fi
yarn react-native run-ios --scheme "celo-${ENV_NAME}" --configuration "$CONFIGURATION" --no-packager "${simulator_param}"

else
Expand Down
7 changes: 6 additions & 1 deletion src/map/MapBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ const MapBottomSheet = ({ mapRef }: Props) => {

const renderHandle = useCallback(
(props) => (
<MapSheetHandle title={MapCategory.All} {...props} ref={bottomSheetRef} mapRef={mapRef} />
<MapSheetHandle
title={MapCategory.All}
{...props}
sheetRef={bottomSheetRef}
mapRef={mapRef}
/>
),
[]
)
Expand Down
11 changes: 6 additions & 5 deletions src/map/MapScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const MapScreen = () => {
if (!mapCategory.includes(MapCategory.Vendor)) return
return (
<>
{vendors.map((vendor: VendorWithLocation) => (
{vendors.map((vendor: VendorWithLocation, i: number) => (
<VendorMarker
title={vendor.title}
coordinate={vendor.location}
key={vendor.title}
key={vendor.title + i}
description={vendor.subtitle}
onPress={() => dispatch(setCurrentVendor(vendor))}
color={currentVendor === vendor ? Colors.activeMarker : Colors.inactiveVendor}
Expand All @@ -50,12 +50,12 @@ const MapScreen = () => {
if (!mapCategory.includes(MapCategory.FoodForest)) return // forest is selected
return (
<>
{map(forests, (forest: FoodForest) => {
{map(forests, (forest: FoodForest, i: number) => {
return (
<ForestMarker
title={forest.title}
coordinate={forest.ingress || { latitude: 0, longitude: 0 }}
key={forest.title}
key={forest.title + i}
onPress={() => dispatch(setFoodForest(forest))}
/>
)
Expand All @@ -68,9 +68,10 @@ const MapScreen = () => {
if (!mapCategory.includes(MapCategory.FoodForest)) return
return (
<>
{map(forests, (forest: FoodForest) => {
{map(forests, (forest: FoodForest, i: number) => {
return (
<Geojson
key={i}
geojson={forest.data}
strokeColor={Colors.goldUI}
strokeWidth={StyleSheet.hairlineWidth}
Expand Down
32 changes: 18 additions & 14 deletions src/map/MapSheetHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet'
import { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types'
import Geolocation from '@react-native-community/geolocation'
import { includes, remove, valuesIn } from 'lodash'
import React, { memo, useMemo } from 'react'
import { StyleProp, StyleSheet, TouchableOpacity, View, ViewStyle } from 'react-native'
Expand All @@ -12,11 +12,7 @@ import Searchbar from 'src/components/SearchBar'
import FindMy from 'src/icons/FindMy'
import { removeMapCategory, setMapCategory } from 'src/map/actions'
import { MapCategory } from 'src/map/constants'
import {
currentForestSelector,
currentMapCategorySelector,
userLocationSelector,
} from 'src/map/selector'
import { currentForestSelector, currentMapCategorySelector } from 'src/map/selector'
import variables from 'src/styles/variables'
import { currentVendorSelector } from 'src/vendors/selector'

Expand All @@ -28,7 +24,6 @@ interface CustomHandleProps extends BottomSheetHandleProps {

const MapSheetHandle: React.FC<CustomHandleProps> = ({ title, style, animatedIndex, mapRef }) => {
const dispatch = useDispatch()
const userLocation = useSelector(userLocationSelector)
const mapCategory = useSelector(currentMapCategorySelector)
const currentVendor = useSelector(currentVendorSelector)
const currentForest = useSelector(currentForestSelector)
Expand All @@ -52,9 +47,9 @@ const MapSheetHandle: React.FC<CustomHandleProps> = ({ title, style, animatedInd
const renderFilters = () => {
return (
<>
{remove(valuesIn(MapCategory), (x) => x !== 'All').map((cat: string) => {
{remove(valuesIn(MapCategory), (x) => x !== 'All').map((cat: string, i: number) => {
return (
<View style={styles.filterRow}>
<View style={styles.filterRow} key={i}>
<MapFilterButton
text={cat}
active={mapCategory.includes(cat as MapCategory)}
Expand All @@ -71,11 +66,20 @@ const MapSheetHandle: React.FC<CustomHandleProps> = ({ title, style, animatedInd
}

const handleFindMy = () => {
mapRef.current?.animateToRegion({
...userLocation,
latitudeDelta: 0.005,
longitudeDelta: 0.005,
})
// @note Get user's current location using geolocation
Geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude } = position.coords
mapRef.current?.animateToRegion({
...{ latitude, longitude },
latitudeDelta: 0.005,
longitudeDelta: 0.005,
})
},
(error) => {
console.error('error', error)
}
)
}

// render
Expand Down
37 changes: 3 additions & 34 deletions src/map/saga.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import Geolocation from '@react-native-community/geolocation'
import { map } from 'lodash'
import { LatLng } from 'react-native-maps'
import { fork, put, select, spawn, takeEvery, takeLatest } from 'redux-saga/effects'
import { Actions as AppActions } from 'src/app/actions'
import { activeScreenSelector } from 'src/app/selectors'
import {
Actions,
setFilteredVendors,
setFoodForests,
setLocationError,
setSearchQuery,
setUserLocation,
} from 'src/map/actions'
import { Actions, setFilteredVendors, setFoodForests, setSearchQuery } from 'src/map/actions'
import { FoodForest } from 'src/map/constants'
import { FoodForests } from 'src/map/types'
import { filterVendors } from 'src/map/utils'
import { Screens } from 'src/navigator/Screens'
import { watchFetchVendors } from 'src/vendors/saga'
import { vendorsSelector } from 'src/vendors/selector'

const TAG = 'map/saga'

function* watchMapFilter(action: any): any {
const vendors = yield select(vendorsSelector)
const filteredVendors = filterVendors(action.searchQuery, vendors)
Expand Down Expand Up @@ -55,29 +46,7 @@ export function* mapSearchSaga() {
yield takeLatest(AppActions.ACTIVE_SCREEN_CHANGED, resetMapFilter)
}

export function* findUserLocation(): any {
const activeScreen = yield select(activeScreenSelector)
if (activeScreen !== Screens.Map) return

let error: any
let coordinates: LatLng | undefined = undefined
Geolocation.getCurrentPosition(
(position) => {
coordinates = position.coords as LatLng
},
(_error) => {
error = _error
},
{
enableHighAccuracy: true,
}
)
if (error && !coordinates) yield put(setLocationError(JSON.stringify(error)))
yield put(setUserLocation(coordinates || {}))
}

export function* mapSaga() {
yield spawn(mapServiceSaga)
yield spawn(mapSearchSaga)
yield takeLatest(AppActions.ACTIVE_SCREEN_CHANGED, findUserLocation)
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2317,9 +2317,9 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@capsule/client@github:capsule-org/user-management-client":
"@capsule/client@capsule-org/user-management-client":
version "0.0.1"
resolved "git+ssh://[email protected]/capsule-org/user-management-client.git#e54a69a6cd30d790409ba410226adb9246092543"
resolved "git+ssh://[email protected]/capsule-org/user-management-client.git#51de65165aadec790430f29fb97fef3f2c716bd5"
dependencies:
axios "^0.27.2"

Expand Down

0 comments on commit 1e48962

Please sign in to comment.