[AAv2] Integrate on-device APIs (#9564)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,8 @@ import {type Geolocation} from '#/geolocation/types'
|
||||
const localEnabled = false
|
||||
export const enabled = IS_DEV && (localEnabled || aaDebug.geolocation)
|
||||
export const geolocation: Geolocation = aaDebug.geolocation ?? {
|
||||
countryCode: 'US',
|
||||
regionCode: 'TX',
|
||||
countryCode: 'AA',
|
||||
regionCode: undefined,
|
||||
}
|
||||
|
||||
const deviceLocalEnabled = false
|
||||
@@ -14,8 +14,8 @@ export const deviceGeolocation: Geolocation | undefined =
|
||||
aaDebug.deviceGeolocation ||
|
||||
(deviceLocalEnabled
|
||||
? {
|
||||
countryCode: 'US',
|
||||
regionCode: 'TX',
|
||||
countryCode: 'AA',
|
||||
regionCode: undefined,
|
||||
}
|
||||
: undefined)
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ export * from '#/geolocation/types'
|
||||
const GeolocationContext = createContext<Geolocation>({
|
||||
countryCode: undefined,
|
||||
regionCode: undefined,
|
||||
serviceGeolocation: undefined,
|
||||
deviceGeolocation: undefined,
|
||||
})
|
||||
|
||||
const DeviceGeolocationAPIContext = createContext<{
|
||||
@@ -44,7 +46,17 @@ export function Provider({children}: {children: ReactNode}) {
|
||||
'deviceGeolocation',
|
||||
])
|
||||
const geolocation = useMemo(() => {
|
||||
return mergeGeolocations(deviceGeolocation, geolocationService)
|
||||
const geo = mergeGeolocations(deviceGeolocation, geolocationService)
|
||||
// create new objects to avoid cyclical references
|
||||
geo.serviceGeolocation = {
|
||||
countryCode: geolocationService?.countryCode,
|
||||
regionCode: geolocationService?.regionCode,
|
||||
}
|
||||
geo.deviceGeolocation = {
|
||||
countryCode: deviceGeolocation?.countryCode,
|
||||
regionCode: deviceGeolocation?.regionCode,
|
||||
}
|
||||
return geo
|
||||
}, [deviceGeolocation, geolocationService])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
export type Geolocation = {
|
||||
countryCode: string | undefined
|
||||
regionCode: string | undefined
|
||||
serviceGeolocation?: Geolocation
|
||||
deviceGeolocation?: Geolocation
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user