sharetribe / ftw-daily

Sharetribe Flex Template for Web
Other
102 stars 944 forks source link

The function 'routeConfiguration' does not work. #1601

Open deepakrh185 opened 11 months ago

deepakrh185 commented 11 months ago

When attempting to access the current location using the build browser navigator function, an error is thrown stating that navigator is undefined. To resolve this issue, the following code was added: if (typeof navigator !== 'undefined'). However, after implementing this fix, the application now throws an error stating that routeConfiguration is not a function

image

Steps to reproduce the behaviour:

  1. Create a new file called useCurrentLocation.js with this code
    
    import { types as sdkTypes } from '../util/sdkLoader';
    const { LatLng } = sdkTypes;

export const useCurrentLocation = async () => { if (typeof navigator !== 'undefined') { if (!('geolocation' in navigator)) { throw new Error('Geolocation not available in the browser'); }

const options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0,
};

try {
  const position = await new Promise((resolve, reject) => {
    navigator?.geolocation?.getCurrentPosition(resolve, reject, options);
  });

  return new LatLng(position.coords.latitude, position.coords.longitude);
} catch (error) {
  console.log('error->>>Location', error);
  return error.message;
}

} else { return; } };

2.Call the function in Searchpage.duck.js to access the current Location

const { useCurrentLocation } = await import('../../hooks/useCurrentLocation'); const getCurrentLocation = useCurrentLocation(); async function fetchResults() { const latlng = await getCurrentLocation; console.log(latlng); const results = { address: '', origin: latlng, bounds: locationBounds( latlng == 'User denied Geolocation' ? null : latlng, config.maps.search.currentLocationBoundsDistance ), }; return results; }



**Expected behavior** This should run without error when `npm run dev-server`

**Screenshots** 
![image](https://github.com/sharetribe/ftw-daily/assets/71048565/a60d59f3-e7d2-4a78-821f-3e0c54a9591e)