Colota - Android GPS Location tracker
feat: highlight tapped point on location history map
Max Dietriche1448875b8da
diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsxindex 6b7b3437..c1a2ee76 100644--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx@@ -39,15 +39,15 @@ const trackPointStyle: any = {interface Props {locations: TrackLocation[]- selectedPoint: { latitude: number; longitude: number } | nullcolors: ThemeColorstrips?: Trip[]fitVersion?: number}-export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }: Props) {+export function TrackMap({ locations, colors, trips, fitVersion }: Props) {const mapRef = useRef<ColotaMapRef>(null)const [isCentered, setIsCentered] = useState(true)+ const [selectedPoint, setSelectedPoint] = useState<{ latitude: number; longitude: number } | null>(null)const [popup, setPopup] = useState<{coordinate: [number, number]speed: number@@ -78,22 +78,12 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }const handleMapReady = useCallback(() => setMapReady(true), [])- // Clear popup when underlying locations change (new day / different trip)+ // Clear popup and highlight when underlying locations change (new day / different trip)useEffect(() => {setPopup(null)+ setSelectedPoint(null)}, [locations])- // Zoom to selected point from table tap- useEffect(() => {- if (selectedPoint && mapRef.current?.camera) {- mapRef.current.camera.flyTo({- center: [selectedPoint.longitude, selectedPoint.latitude],- zoom: 17,- duration: 500- })- }- }, [selectedPoint])-const handleFitTrack = useCallback(() => {if (bounds && mapRef.current?.camera) {mapRef.current.camera.fitBounds([bounds.sw[0], bounds.sw[1], bounds.ne[0], bounds.ne[1]], {@@ -187,6 +177,7 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }lastPointPressRef.current = Date.now()const geom = feature.geometry as GeoJSON.Pointconst coord = geom.coordinates as [number, number]+ setSelectedPoint({ longitude: coord[0], latitude: coord[1] })setPopup({coordinate: coord,speed: feature.properties.speed,@@ -202,6 +193,7 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }const handleMapPress = useCallback(() => {if (Date.now() - lastPointPressRef.current < 200) returnsetPopup(null)+ setSelectedPoint(null)}, [])const initialCenter = useMemo(@@ -272,7 +264,10 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }{popup.timestamp ? new Date(popup.timestamp * 1000).toLocaleTimeString() : "-"}</Text><Pressable- onPress={() => setPopup(null)}+ onPress={() => {+ setPopup(null)+ setSelectedPoint(null)+ }}hitSlop={HIT_SLOP_MD}style={({ pressed }) => pressed && { opacity: colors.pressedOpacity }}>diff --git a/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsxindex 5aabb70a..35ddf8a3 100644--- a/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx+++ b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx@@ -92,18 +92,18 @@ describe("TrackMap auto-fit", () => {const locsA = [loc(48.1, 11.5), loc(48.2, 11.6)]const locsB = [loc(52.5, 13.4), loc(52.6, 13.5)]- const { rerender } = render(<TrackMap locations={locsA} selectedPoint={null} colors={colors} fitVersion={1} />)+ const { rerender } = render(<TrackMap locations={locsA} colors={colors} fitVersion={1} />)expect(mockFitBounds).toHaveBeenCalledTimes(1)// Switch to empty dayact(() => {- rerender(<TrackMap locations={[]} selectedPoint={null} colors={colors} fitVersion={2} />)+ rerender(<TrackMap locations={[]} colors={colors} fitVersion={2} />)})expect(mockFitBounds).toHaveBeenCalledTimes(1) // no new fit on empty// Switch to another non-empty day - the regression targetact(() => {- rerender(<TrackMap locations={locsB} selectedPoint={null} colors={colors} fitVersion={3} />)+ rerender(<TrackMap locations={locsB} colors={colors} fitVersion={3} />)})expect(mockFitBounds).toHaveBeenCalledTimes(2)})diff --git a/apps/mobile/src/screens/LocationInspectorScreen.tsx b/apps/mobile/src/screens/LocationInspectorScreen.tsxindex bccf36a4..1c659366 100644--- a/apps/mobile/src/screens/LocationInspectorScreen.tsx+++ b/apps/mobile/src/screens/LocationInspectorScreen.tsx@@ -239,7 +239,6 @@ export function LocationHistoryScreen({ navigation, route }: RootScreenProps<"Lo{calendarPicker}<TrackMaplocations={mapLocations}- selectedPoint={null}colors={colors}trips={selectedTrip ? undefined : trips}fitVersion={fitVersion}diff --git a/apps/mobile/src/screens/TripDetailScreen.tsx b/apps/mobile/src/screens/TripDetailScreen.tsxindex 39130581..65dab5a4 100644--- a/apps/mobile/src/screens/TripDetailScreen.tsx+++ b/apps/mobile/src/screens/TripDetailScreen.tsx@@ -147,7 +147,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De<ScrollView contentContainerStyle={styles.content}>{/* Map */}<View style={styles.mapContainer}>- <TrackMap locations={trip.locations} selectedPoint={null} colors={colors} fitVersion={1} />+ <TrackMap locations={trip.locations} colors={colors} fitVersion={1} /></View>{/* Header */}