Colota - Android GPS Location tracker
fix: keep TrackMap mounted on empty day so auto-fit works on next select Closes #275
Max Dietrichcc370ca2f314
diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsxindex 590dfde7..5ba9b8a8 100644--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx@@ -243,24 +243,23 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }])- if (locations.length === 0) {- return (- <View style={[styles.emptyContainer, { backgroundColor: colors.card, borderRadius: colors.borderRadius }]}>- <View style={[styles.iconCircle, { backgroundColor: colors.border }]}>- <MapPinOff size={32} color={colors.textSecondary} />- </View>- <Text style={[styles.emptyTitle, { color: colors.text }]}>No Locations</Text>- <Text style={[styles.emptySubtext, { color: colors.textSecondary }]}>No tracked locations for this day.</Text>- </View>- )- }+ const isEmpty = locations.length === 0return (<View style={styles.container}>{mapView}- {/* Point detail popup */}- {popup && (+ {isEmpty && (+ <View style={[styles.emptyOverlay, { backgroundColor: colors.card, borderRadius: colors.borderRadius }]}>+ <View style={[styles.iconCircle, { backgroundColor: colors.border }]}>+ <MapPinOff size={32} color={colors.textSecondary} />+ </View>+ <Text style={[styles.emptyTitle, { color: colors.text }]}>No Locations</Text>+ <Text style={[styles.emptySubtext, { color: colors.textSecondary }]}>No tracked locations for this day.</Text>+ </View>+ )}++ {!isEmpty && popup && (<View style={[styles.popupCard, { backgroundColor: colors.card, borderColor: colors.border }]}><View style={styles.popupHeader}><Text style={[styles.popupTime, { color: colors.text }]}>@@ -294,10 +293,9 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }</View>)}- <MapCenterButton visible={!isCentered} onPress={handleFitTrack} />+ {!isEmpty && <MapCenterButton visible={!isCentered} onPress={handleFitTrack} />}- {/* Trip legend */}- {trips && trips.length > 1 && (+ {!isEmpty && trips && trips.length > 1 && (<View style={[styles.legend, { backgroundColor: colors.card, borderColor: colors.border }]}>{trips.map((trip) => (<View key={trip.index} style={styles.legendItem}>@@ -316,11 +314,16 @@ const styles = StyleSheet.create({flex: 1,overflow: "hidden"},- emptyContainer: {- flex: 1,+ emptyOverlay: {+ position: "absolute",+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,justifyContent: "center",alignItems: "center",- padding: 24+ padding: 24,+ zIndex: 20},iconCircle: {width: 64,diff --git a/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsxnew file mode 100644index 00000000..6d48e972--- /dev/null+++ b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx@@ -0,0 +1,111 @@+import React from "react"+import { render, act } from "@testing-library/react-native"+import { TrackMap } from "../TrackMap"++const mockFitBounds = jest.fn()++jest.mock("../../map/ColotaMapView", () => {+ const R = require("react")+ const { View } = require("react-native")+ return {+ __esModule: true,+ ColotaMapView: R.forwardRef(function MockColotaMapView(props: any, ref: any) {+ const onMapReady = props.onMapReady+ R.useImperativeHandle(ref, () => ({+ camera: { fitBounds: mockFitBounds },+ mapView: null+ }))+ R.useEffect(() => {+ onMapReady?.()+ }, [onMapReady])+ return R.createElement(View, { testID: "MockColotaMapView" }, props.children)+ })+ }+})++jest.mock("@maplibre/maplibre-react-native", () => {+ const R = require("react")+ const { View } = require("react-native")+ const stub = (name: string) => {+ const Stub = (props: any) => R.createElement(View, { testID: name }, props.children)+ Stub.displayName = name+ return Stub+ }+ return {+ ShapeSource: stub("ShapeSource"),+ LineLayer: stub("LineLayer"),+ CircleLayer: stub("CircleLayer")+ }+})++jest.mock("../../map/MapCenterButton", () => ({+ MapCenterButton: () => null+}))++jest.mock("../../../../styles/typography", () => ({+ fonts: { regular: {}, bold: {}, semiBold: {} }+}))++jest.mock("../../../../utils/geo", () => ({+ getSpeedUnit: () => ({ factor: 3.6, unit: "km/h" })+}))++jest.mock("../../../../utils/trips", () => ({+ getTripColor: () => "#000"+}))++const colors = {+ primary: "#00f",+ card: "#fff",+ border: "#ccc",+ text: "#000",+ textSecondary: "#666",+ borderRadius: 8,+ pressedOpacity: 0.6+} as any++const loc = (lat: number, lon: number) => ({+ latitude: lat,+ longitude: lon,+ accuracy: 5,+ timestamp: 1000,+ altitude: 100,+ speed: 0,+ bearing: 0,+ battery: 80,+ battery_status: 2+})++describe("TrackMap auto-fit", () => {+ beforeEach(() => {+ mockFitBounds.mockClear()+ jest.spyOn(globalThis, "requestAnimationFrame").mockImplementation((cb: any) => {+ cb(0)+ return 0+ })+ })++ afterEach(() => {+ jest.restoreAllMocks()+ })++ it("fits bounds when switching from empty day to non-empty day", () => {+ 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} />)+ expect(mockFitBounds).toHaveBeenCalledTimes(1)++ // Switch to empty day+ act(() => {+ rerender(<TrackMap locations={[]} selectedPoint={null} colors={colors} fitVersion={2} />)+ })+ expect(mockFitBounds).toHaveBeenCalledTimes(1) // no new fit on empty++ // Switch to another non-empty day - the regression target+ act(() => {+ rerender(<TrackMap locations={locsB} selectedPoint={null} colors={colors} fitVersion={3} />)+ })+ expect(mockFitBounds).toHaveBeenCalledTimes(2)+ })+})