@@ -4,9 +4,9 @@ import React, { useEffect, useMemo, useState } from 'react';
44import { useTranslation } from 'react-i18next' ;
55import { Pressable , RefreshControl , View } from 'react-native' ;
66
7- import { RouteCard } from '@/components/routes/route-card' ;
87import { Loading } from '@/components/common/loading' ;
98import ZeroState from '@/components/common/zero-state' ;
9+ import { RouteCard } from '@/components/routes/route-card' ;
1010import { Badge , BadgeText } from '@/components/ui/badge' ;
1111import { Box } from '@/components/ui/box' ;
1212import { Fab , FabIcon } from '@/components/ui/fab' ;
@@ -33,10 +33,7 @@ export default function Routes() {
3333 const fetchUnits = useUnitsStore ( ( state ) => state . fetchUnits ) ;
3434 const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
3535
36- const unitMap = useMemo (
37- ( ) => Object . fromEntries ( units . map ( ( u ) => [ u . UnitId , u . Name ] ) ) ,
38- [ units ]
39- ) ;
36+ const unitMap = useMemo ( ( ) => Object . fromEntries ( units . map ( ( u ) => [ u . UnitId , u . Name ] ) ) , [ units ] ) ;
4037
4138 useEffect ( ( ) => {
4239 fetchAllRoutePlans ( ) ;
@@ -58,9 +55,7 @@ export default function Routes() {
5855 const handleRoutePress = ( route : RoutePlanResultData ) => {
5956 if ( activeInstance && activeInstance . RoutePlanId === route . RoutePlanId ) {
6057 const iid = activeInstance . RouteInstanceId ;
61- const url = iid && iid !== 'undefined'
62- ? `/routes/active?planId=${ route . RoutePlanId } &instanceId=${ iid } `
63- : `/routes/active?planId=${ route . RoutePlanId } ` ;
58+ const url = iid && iid !== 'undefined' ? `/routes/active?planId=${ route . RoutePlanId } &instanceId=${ iid } ` : `/routes/active?planId=${ route . RoutePlanId } ` ;
6459 router . push ( url as any ) ;
6560 } else {
6661 router . push ( `/routes/start?planId=${ route . RoutePlanId } ` as any ) ;
@@ -73,12 +68,8 @@ export default function Routes() {
7368 const q = searchQuery . toLowerCase ( ) ;
7469 return active . filter ( ( route ) => {
7570 const isRouteMyUnit = route . UnitId != null && String ( route . UnitId ) === String ( activeUnitId ) ;
76- const unitName = route . UnitId != null ? ( unitMap [ route . UnitId ] || ( isRouteMyUnit ? ( activeUnit ?. Name ?? '' ) : '' ) ) : '' ;
77- return (
78- route . Name . toLowerCase ( ) . includes ( q ) ||
79- ( route . Description ?. toLowerCase ( ) || '' ) . includes ( q ) ||
80- unitName . toLowerCase ( ) . includes ( q )
81- ) ;
71+ const unitName = route . UnitId != null ? unitMap [ route . UnitId ] || ( isRouteMyUnit ? ( activeUnit ?. Name ?? '' ) : '' ) : '' ;
72+ return route . Name . toLowerCase ( ) . includes ( q ) || ( route . Description ?. toLowerCase ( ) || '' ) . includes ( q ) || unitName . toLowerCase ( ) . includes ( q ) ;
8273 } ) ;
8374 } , [ routePlans , searchQuery , unitMap , activeUnitId , activeUnit ] ) ;
8475
@@ -100,29 +91,23 @@ export default function Routes() {
10091 < Pressable
10192 onPress = { ( ) => {
10293 const iid = activeInstance . RouteInstanceId ;
103- const url = iid && iid !== 'undefined'
104- ? `/routes/active?planId=${ activeInstance . RoutePlanId } &instanceId=${ iid } `
105- : `/routes/active?planId=${ activeInstance . RoutePlanId } ` ;
94+ const url = iid && iid !== 'undefined' ? `/routes/active?planId=${ activeInstance . RoutePlanId } &instanceId=${ iid } ` : `/routes/active?planId=${ activeInstance . RoutePlanId } ` ;
10695 router . push ( url as any ) ;
10796 } }
10897 >
10998 < Box className = "mb-3 rounded-xl border-2 border-green-500 bg-green-50 p-4 dark:bg-green-900/20" >
11099 < HStack className = "items-center justify-between" >
111100 < HStack className = "items-center space-x-2" >
112101 < Navigation size = { 20 } color = "#22c55e" />
113- < Text className = "text-base font-bold text-green-800 dark:text-green-200" >
114- { activeInstance . RoutePlanName || t ( 'routes.active_route' ) }
115- </ Text >
102+ < Text className = "text-base font-bold text-green-800 dark:text-green-200" > { activeInstance . RoutePlanName || t ( 'routes.active_route' ) } </ Text >
116103 </ HStack >
117104 < Badge className = "bg-green-500" >
118105 < BadgeText className = "text-white" > { t ( 'routes.active' ) } </ BadgeText >
119106 </ Badge >
120107 </ HStack >
121108 < Text className = "mt-1 text-sm text-green-700 dark:text-green-300" >
122109 { t ( 'routes.progress' , {
123- percent : activeInstance . StopsTotal
124- ? Math . round ( ( ( activeInstance . StopsCompleted ?? 0 ) / activeInstance . StopsTotal ) * 100 )
125- : 0 ,
110+ percent : activeInstance . StopsTotal ? Math . round ( ( ( activeInstance . StopsCompleted ?? 0 ) / activeInstance . StopsTotal ) * 100 ) : 0 ,
126111 } ) }
127112 </ Text >
128113 </ Box >
@@ -131,29 +116,16 @@ export default function Routes() {
131116 }
132117 renderItem = { ( { item } : { item : RoutePlanResultData } ) => {
133118 const isMyUnit = item . UnitId != null && String ( item . UnitId ) === String ( activeUnitId ) ;
134- const unitName = item . UnitId != null
135- ? ( unitMap [ item . UnitId ] || ( isMyUnit ? ( activeUnit ?. Name ?? '' ) : '' ) )
136- : '' ;
119+ const unitName = item . UnitId != null ? unitMap [ item . UnitId ] || ( isMyUnit ? ( activeUnit ?. Name ?? '' ) : '' ) : '' ;
137120 return (
138121 < Pressable onPress = { ( ) => handleRoutePress ( item ) } >
139- < RouteCard
140- route = { item }
141- isActive = { ! ! activeInstance && activeInstance . RoutePlanId === item . RoutePlanId }
142- unitName = { unitName || undefined }
143- isMyUnit = { isMyUnit }
144- />
122+ < RouteCard route = { item } isActive = { ! ! activeInstance && activeInstance . RoutePlanId === item . RoutePlanId } unitName = { unitName || undefined } isMyUnit = { isMyUnit } />
145123 </ Pressable >
146124 ) ;
147125 } }
148126 keyExtractor = { ( item : RoutePlanResultData ) => item . RoutePlanId }
149127 refreshControl = { < RefreshControl refreshing = { isLoading } onRefresh = { handleRefresh } /> }
150- ListEmptyComponent = {
151- < ZeroState
152- heading = { t ( 'routes.no_routes' ) }
153- description = { t ( 'routes.no_routes_description_all' ) }
154- icon = { RefreshCcwDotIcon }
155- />
156- }
128+ ListEmptyComponent = { < ZeroState heading = { t ( 'routes.no_routes' ) } description = { t ( 'routes.no_routes_description_all' ) } icon = { RefreshCcwDotIcon } /> }
157129 contentContainerStyle = { { paddingBottom : 20 } }
158130 />
159131 ) ;
0 commit comments