Skip to content

Commit

Permalink
chore: remove circular deps
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasburtey committed Mar 15, 2024
1 parent 3276374 commit 932af0e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/components/map-component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PermissionStatus, RESULTS, request } from "react-native-permissions"
import { useApolloClient } from "@apollo/client"
import { updateMapLastCoords } from "@app/graphql/client-only-query"
import { BusinessMapMarkersQuery, MapMarker } from "@app/graphql/generated"
import { LOCATION_PERMISSION, getUserRegion } from "@app/screens/map-screen/map-screen"
import { LOCATION_PERMISSION, getUserRegion } from "@app/screens/map-screen/functions"
import { isIOS } from "@rneui/base"
import { makeStyles, useTheme } from "@rneui/themed"

Expand Down
33 changes: 33 additions & 0 deletions app/screens/map-screen/functions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Region } from "react-native-maps"
import { PERMISSIONS } from "react-native-permissions"

import { isIos } from "@app/utils/helper"
import Geolocation from "@react-native-community/geolocation"

export const LOCATION_PERMISSION = isIos
? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE
: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION

export const getUserRegion = (callback: (region?: Region) => void) => {
try {
Geolocation.getCurrentPosition(
(data: GeolocationPosition) => {
if (data) {
const region: Region = {
latitude: data.coords.latitude,
longitude: data.coords.longitude,
latitudeDelta: 0.02,
longitudeDelta: 0.02,
}
callback(region)
}
},
() => {
callback(undefined)
},
{ timeout: 5000 },
)
} catch (e) {
callback(undefined)
}
}
32 changes: 2 additions & 30 deletions app/screens/map-screen/map-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react"
// eslint-disable-next-line react-native/split-platform-components
import { Alert, Dimensions } from "react-native"
import { Region, MapMarker as MapMarkerType } from "react-native-maps"
import { check, PERMISSIONS, PermissionStatus, RESULTS } from "react-native-permissions"
import { check, PermissionStatus, RESULTS } from "react-native-permissions"

import { gql } from "@apollo/client"
import MapComponent from "@app/components/map-component"
Expand All @@ -15,7 +15,6 @@ import {
import { useIsAuthed } from "@app/graphql/is-authed-context"
import useDeviceLocation from "@app/hooks/use-device-location"
import { useI18nContext } from "@app/i18n/i18n-react"
import { isIos } from "@app/utils/helper"
import Geolocation from "@react-native-community/geolocation"
import { useFocusEffect } from "@react-navigation/native"
import { StackNavigationProp } from "@react-navigation/stack"
Expand All @@ -25,6 +24,7 @@ import { Screen } from "../../components/screen"
import { RootStackParamList } from "../../navigation/stack-param-lists"
import { toastShow } from "../../utils/toast"
import { PhoneLoginInitiateType } from "../phone-auth-screen"
import { LOCATION_PERMISSION, getUserRegion } from "./functions"

const EL_ZONTE_COORDS = {
latitude: 13.496743,
Expand All @@ -33,10 +33,6 @@ const EL_ZONTE_COORDS = {
longitudeDelta: 0.02,
}

export const LOCATION_PERMISSION = isIos
? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE
: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION

// essentially calculates zoom for location being set based on country
const { height, width } = Dimensions.get("window")
const LATITUDE_DELTA = 15 // <-- decrease for more zoom
Expand All @@ -53,30 +49,6 @@ Geolocation.setRNConfiguration({
locationProvider: "auto",
})

export const getUserRegion = (callback: (region?: Region) => void) => {
try {
Geolocation.getCurrentPosition(
(data: GeolocationPosition) => {
if (data) {
const region: Region = {
latitude: data.coords.latitude,
longitude: data.coords.longitude,
latitudeDelta: 0.02,
longitudeDelta: 0.02,
}
callback(region)
}
},
() => {
callback(undefined)
},
{ timeout: 5000 },
)
} catch (e) {
callback(undefined)
}
}

gql`
query businessMapMarkers {
businessMapMarkers {
Expand Down

0 comments on commit 932af0e

Please sign in to comment.