11import { useCallback , useEffect , useMemo , useState } from 'react' ;
22import { validateWithinRadius } from '@/validation/validateGeolocation' ;
3- import { ACCURACY_LIMIT_M } from '@/constants/geolocation' ;
3+ import { VALIDATION_RADIUS_M } from '@/constants/geolocation' ;
44
55type GeoResult = {
6- ok : boolean ;
6+ isOk : boolean ;
77 distanceMeters : number ;
88 accuracyMeters : number | null ;
99} ;
@@ -12,12 +12,11 @@ export function useGeoValidation(options?: {
1212 accuracyLimitMeters ?: number ;
1313 geolocationOptions ?: PositionOptions ;
1414} ) {
15- const accuracyLimit = options ?. accuracyLimitMeters ?? ACCURACY_LIMIT_M ;
15+ const accuracyLimit = options ?. accuracyLimitMeters ?? VALIDATION_RADIUS_M ;
1616 const geoOptions = useMemo (
1717 ( ) =>
1818 options ?. geolocationOptions ?? {
19- // koristit ce vise baterije radi gps-a, mozda nam se neisplati
20- // enableHighAccuracy: true,
19+ enableHighAccuracy : true ,
2120 timeout : 15000 ,
2221 maximumAge : 0 ,
2322 } ,
@@ -42,28 +41,29 @@ export function useGeoValidation(options?: {
4241 const accuracy = pos . coords . accuracy ?? null ;
4342
4443 // Reject low-accuracy fixes first
45- if ( accuracy == null || accuracy > accuracyLimit ) {
44+ if ( ! accuracy || accuracy > accuracyLimit ) {
4645 const msg = `Location accuracy too low (${ accuracy ? Math . round ( accuracy ) : '?' } m).` ;
4746 setIsOk ( false ) ;
4847 setError ( msg ) ;
4948 setResult (
50- accuracy == null
49+ ! accuracy
5150 ? null
52- : { ok : false , distanceMeters : NaN , accuracyMeters : accuracy } ,
51+ : { isOk : false , distanceMeters : NaN , accuracyMeters : accuracy } ,
5352 ) ;
5453 return ;
5554 }
5655
57- const r = validateWithinRadius ( pos . coords ) ;
56+ const { isOk , distanceMeters } = validateWithinRadius ( pos . coords ) ;
5857
5958 const payload : GeoResult = {
60- ok : r . ok ,
61- distanceMeters : r . distanceMeters ,
59+ isOk ,
60+ distanceMeters,
6261 accuracyMeters : accuracy ,
6362 } ;
6463
6564 setResult ( payload ) ;
66- setIsOk ( r . ok ) ;
65+ setIsOk ( isOk ) ;
66+ console . log ( 'Geo validation result:' , payload ) ;
6767 } ,
6868 ( err ) => {
6969 setIsOk ( false ) ;
0 commit comments