@@ -42,7 +42,7 @@ const App = () => {
42
42
const [ isAvailableState , setIsAvailableState ] = useState ( false ) ;
43
43
const [ isTrackingState , setIsTrackingState ] = useState ( false ) ;
44
44
const [ locationState , setLocationState ] = useState ( '' ) ;
45
- const [ ordersState , setOrdersState ] = useState ( new Map < string , Order > ( ) ) ;
45
+ const [ ordersState , setOrdersState ] = useState ( 'N/A' ) ;
46
46
47
47
const errorsListener = useRef < EmitterSubscription | null | undefined > ( null ) ;
48
48
const isAvailableListener = useRef < EmitterSubscription | null | undefined > (
@@ -88,7 +88,7 @@ const App = () => {
88
88
* (to remove the link between the device and the worker)
89
89
**/
90
90
HyperTrack . setWorkerHandle (
91
- `test_driver_quickstart_react_native_ ${ platformName } ` ,
91
+ `test_worker_quickstart_react_native_ ${ platformName } ` ,
92
92
) ;
93
93
console . log ( 'workerHandle is set' ) ;
94
94
@@ -125,9 +125,10 @@ const App = () => {
125
125
) ;
126
126
127
127
ordersListener . current = HyperTrack . subscribeToOrders (
128
- ( orders : Map < string , Order > ) => {
128
+ async ( orders : Map < string , Order > ) => {
129
129
console . log ( 'Listener orders: ' , orders ) ;
130
- setOrdersState ( orders ) ;
130
+ const text = await getOrdersResponseText ( orders ) ;
131
+ setOrdersState ( text ) ;
131
132
} ,
132
133
) ;
133
134
} catch ( error ) {
@@ -216,7 +217,7 @@ const App = () => {
216
217
const allowMockLocation = await HyperTrack . getAllowMockLocation ( ) ;
217
218
console . log ( 'AllowMockLocation:' , allowMockLocation ) ;
218
219
Alert . alert ( 'AllowMockLocation' , `${ allowMockLocation } ` ) ;
219
- }
220
+ } ;
220
221
221
222
const getErrors = async ( ) => {
222
223
const errors = await HyperTrack . getErrors ( ) ;
@@ -261,7 +262,8 @@ const App = () => {
261
262
const getOrders = async ( ) => {
262
263
const orders = await HyperTrack . getOrders ( ) ;
263
264
console . log ( 'Orders:' , orders ) ;
264
- Alert . alert ( 'Orders' , getOrdersText ( orders ) ) ;
265
+ const text = await getOrdersResponseText ( orders ) ;
266
+ Alert . alert ( 'Orders' , text ) ;
265
267
} ;
266
268
267
269
const locate = async ( ) => {
@@ -284,7 +286,7 @@ const App = () => {
284
286
const setAllowMockLocation = async ( allowMockLocation : boolean ) => {
285
287
HyperTrack . setAllowMockLocation ( allowMockLocation ) ;
286
288
console . log ( 'setAllowMockLocation' , allowMockLocation ) ;
287
- }
289
+ } ;
288
290
289
291
const setIsAvailable = async ( isAvailable : boolean ) => {
290
292
HyperTrack . setIsAvailable ( isAvailable ) ;
@@ -306,16 +308,7 @@ const App = () => {
306
308
</ Text >
307
309
308
310
< Text style = { styles . titleText } > Orders:</ Text >
309
- { Array . from ( ordersState . values ( ) ) . map ( order => {
310
- return (
311
- < View key = { order . orderHandle } >
312
- < Text selectable style = { styles . text } >
313
- { order . orderHandle }
314
- </ Text >
315
- < Text > { getIsInsideGeofenceText ( order . isInsideGeofence ) } </ Text >
316
- </ View >
317
- ) ;
318
- } ) }
311
+ < Text style = { styles . text } > { ordersState } </ Text >
319
312
320
313
< Text style = { styles . titleText } > { 'Location' } </ Text >
321
314
< Text style = { styles . text } > { locationState } </ Text >
@@ -386,9 +379,18 @@ const App = () => {
386
379
</ View >
387
380
388
381
< View style = { styles . buttonWrapper } >
389
- < Button title = "Allow Mock Location" onPress = { ( ) => setAllowMockLocation ( true ) } />
390
- < Button title = "Disallow Mock Location" onPress = { ( ) => setAllowMockLocation ( false ) } />
391
- < Button title = "Get Allow Mock Location" onPress = { getAllowMockLocation } />
382
+ < Button
383
+ title = "Allow Mock Location"
384
+ onPress = { ( ) => setAllowMockLocation ( true ) }
385
+ />
386
+ < Button
387
+ title = "Disallow Mock Location"
388
+ onPress = { ( ) => setAllowMockLocation ( false ) }
389
+ />
390
+ < Button
391
+ title = "Get Allow Mock Location"
392
+ onPress = { getAllowMockLocation }
393
+ />
392
394
</ View >
393
395
</ ScrollView >
394
396
</ SafeAreaView >
@@ -410,6 +412,17 @@ function getLocateResponseText(response: Result<Location, HyperTrackError[]>) {
410
412
}
411
413
}
412
414
415
+ function getLocationErrorResponseText ( locationError : LocationError ) {
416
+ switch ( locationError . type ) {
417
+ case 'notRunning' :
418
+ return 'Not running' ;
419
+ case 'starting' :
420
+ return 'Starting' ;
421
+ case 'errors' :
422
+ return `Errors:\n${ getErrorsText ( locationError . value ) } ` ;
423
+ }
424
+ }
425
+
413
426
function getLocationResponseText (
414
427
response : Result < Location , LocationError > ,
415
428
) : string {
@@ -421,16 +434,7 @@ function getLocationResponseText(
421
434
4 ,
422
435
) } `;
423
436
case 'failure' :
424
- switch ( response . value . type ) {
425
- case 'notRunning' :
426
- return 'Not running' ;
427
- case 'starting' :
428
- return 'Starting' ;
429
- case 'errors' :
430
- return `Errors:\n${ getErrorsText ( response . value . value ) } ` ;
431
- }
432
- default :
433
- return `Unknown response: $response` ;
437
+ return getLocationErrorResponseText ( response . value ) ;
434
438
}
435
439
}
436
440
@@ -445,14 +449,31 @@ function getLocationWithDeviationResponseText(
445
449
4 ,
446
450
) } \nDeviation: ${ response . value . deviation } `;
447
451
case 'failure' :
448
- switch ( response . value . type ) {
449
- case 'notRunning' :
450
- return 'Not running' ;
451
- case 'starting' :
452
- return 'Starting' ;
453
- case 'errors' :
454
- return `Errors:\n${ getErrorsText ( response . value . value ) } ` ;
455
- }
452
+ return getLocationErrorResponseText ( response . value ) ;
453
+ }
454
+ }
455
+
456
+ async function getOrdersResponseText ( orders : Map < string , Order > ) {
457
+ if ( orders . size === 0 ) {
458
+ return 'No orders' ;
459
+ } else {
460
+ return await Promise . all (
461
+ Array . from ( orders ) . map ( async ( [ _ , order ] ) => {
462
+ let isInsideGeofenceText : string ;
463
+ const isInsideGeofence = await order . isInsideGeofence ( ) ;
464
+ switch ( isInsideGeofence . type ) {
465
+ case 'success' :
466
+ isInsideGeofenceText = isInsideGeofence . value . toString ( ) ;
467
+ break ;
468
+ case 'failure' :
469
+ isInsideGeofenceText = getLocationErrorResponseText (
470
+ isInsideGeofence . value ,
471
+ ) ;
472
+ break ;
473
+ }
474
+ return `Order: ${ order . orderHandle } \nIsInsideGeofence: ${ isInsideGeofenceText } ` ;
475
+ } ) ,
476
+ ) . then ( texts => texts . join ( '\n' ) ) ;
456
477
}
457
478
}
458
479
@@ -472,34 +493,6 @@ function getErrorsText(errors: HyperTrackError[]) {
472
493
}
473
494
}
474
495
475
- function getIsInsideGeofenceText (
476
- isInsideResult : Result < boolean , LocationError > ,
477
- ) {
478
- switch ( isInsideResult . type ) {
479
- case 'success' :
480
- return isInsideResult . value . toString ( ) ;
481
- case 'failure' :
482
- switch ( isInsideResult . value . type ) {
483
- case 'notRunning' :
484
- return 'Not running' ;
485
- case 'starting' :
486
- return 'Starting' ;
487
- case 'errors' :
488
- return `Errors:\n${ getErrorsText ( isInsideResult . value . value ) } ` ;
489
- }
490
- }
491
- }
492
-
493
- function getOrdersText ( orders : Map < string , Order > ) {
494
- return Array . from ( orders . values ( ) )
495
- . map ( order => {
496
- return `${ order . orderHandle } :\n\t\t${ getIsInsideGeofenceText (
497
- order . isInsideGeofence ,
498
- ) } `;
499
- } )
500
- . join ( '\n' ) ;
501
- }
502
-
503
496
const styles = StyleSheet . create ( {
504
497
container : {
505
498
flex : 1 ,
0 commit comments