Colota - Android GPS Location tracker
feat: show daily distance in calendar day cells
Max Dietricha96797a12576
diff --git a/apps/mobile/src/components/features/inspector/CalendarPicker.tsx b/apps/mobile/src/components/features/inspector/CalendarPicker.tsxindex f14965ac..6b021d78 100644--- a/apps/mobile/src/components/features/inspector/CalendarPicker.tsx+++ b/apps/mobile/src/components/features/inspector/CalendarPicker.tsx@@ -8,6 +8,7 @@ import { View, Text, Pressable, StyleSheet, LayoutAnimation } from "react-nativeimport { ChevronLeft, ChevronRight, Calendar } from "lucide-react-native"import { ThemeColors } from "../../../types/global"import { fonts } from "../../../styles/typography"+import { formatDistance } from "../../../utils/geo"interface CalendarPickerProps {date: Date@@ -16,6 +17,7 @@ interface CalendarPickerProps {distance?: stringcolors: ThemeColorsdaysWithData: Set<string>+ dayDistances?: Map<string, number>onMonthChange: (year: number, month: number) => voidonPrefetchMonth?: (year: number, month: number) => void}@@ -37,6 +39,7 @@ export function CalendarPicker({distance,colors,daysWithData,+ dayDistances,onMonthChange,onPrefetchMonth}: CalendarPickerProps) {@@ -237,6 +240,7 @@ export function CalendarPicker({const dateKey = formatDateKey(viewYear, viewMonth, cell.day)const hasData = daysWithData.has(dateKey)+ const dist = dayDistances?.get(dateKey)const cellDate = new Date(viewYear, viewMonth, cell.day)const isSelected = isSameDay(cellDate, date)const isCellToday = isSameDay(cellDate, today)@@ -259,15 +263,19 @@ export function CalendarPicker({>{cell.day}</Text>- {hasData && (- <View- style={[- styles.dataDot,- { backgroundColor: isSelected ? colors.textOnPrimary : colors.primary }- ]}- />- )}</View>+ {dist != null && dist > 0 ? (+ <Text+ style={[styles.dayDist, { color: isSelected ? colors.primary : colors.textLight }]}+ numberOfLines={1}+ >+ {formatDistance(dist)}+ </Text>+ ) : hasData ? (+ <View+ style={[styles.dataDot, { backgroundColor: isSelected ? colors.primary : colors.textLight }]}+ />+ ) : null}</Pressable>)})}@@ -365,7 +373,7 @@ const styles = StyleSheet.create({},dayCell: {width: "14.28%",- aspectRatio: 1,+ paddingVertical: 4,alignItems: "center",justifyContent: "center"},@@ -380,10 +388,15 @@ const styles = StyleSheet.create({fontSize: 13,...fonts.regular},+ dayDist: {+ fontSize: 9,+ ...fonts.medium,+ marginTop: 1+ },dataDot: {width: 4,height: 4,borderRadius: 2,- marginTop: 1+ marginTop: 2}})diff --git a/apps/mobile/src/screens/LocationInspectorScreen.tsx b/apps/mobile/src/screens/LocationInspectorScreen.tsxindex 81f6312d..0c31a6f3 100644--- a/apps/mobile/src/screens/LocationInspectorScreen.tsx+++ b/apps/mobile/src/screens/LocationInspectorScreen.tsx@@ -46,6 +46,7 @@ export function LocationHistoryScreen({ navigation, route }: { navigation: any;// Calendar stateconst [daysWithData, setDaysWithData] = useState<Set<string>>(new Set())const daysCache = useRef<Map<string, Set<string>>>(new Map())+ const distanceCache = useRef<Map<string, Map<string, number>>>(new Map())// Trip segmentation from already-fetched day dataconst trips = useMemo(() => segmentTrips(trackLocations), [trackLocations])@@ -76,7 +77,7 @@ export function LocationHistoryScreen({ navigation, route }: { navigation: any;navigation.setOptions({ headerRight })}, [navigation, headerRight])- /** Fetch days-with-data for a month into cache; returns the Set. */+ /** Fetch days-with-data and daily distances for a month into cache. */const prefetchMonth = useCallback(async (year: number, month: number): Promise<Set<string>> => {const key = `${year}-${String(month + 1).padStart(2, "0")}`if (daysCache.current.has(key)) return daysCache.current.get(key)!@@ -85,9 +86,17 @@ export function LocationHistoryScreen({ navigation, route }: { navigation: any;const end = new Date(year, month + 1, 0, 23, 59, 59)const startTs = Math.floor(start.getTime() / 1000)const endTs = Math.floor(end.getTime() / 1000)- const days = await NativeLocationService.getDaysWithData(startTs, endTs)+ const [days, stats] = await Promise.all([+ NativeLocationService.getDaysWithData(startTs, endTs),+ NativeLocationService.getDailyStats(startTs, endTs)+ ])const daySet = new Set(days)daysCache.current.set(key, daySet)+ const distances = new Map<string, number>()+ for (const stat of stats) {+ if (stat.distanceMeters > 0) distances.set(stat.day, stat.distanceMeters)+ }+ distanceCache.current.set(key, distances)return daySet} catch (err) {logger.error("[LocationHistory] Failed to fetch days with data:", err)@@ -194,6 +203,9 @@ export function LocationHistoryScreen({ navigation, route }: { navigation: any;distance={dailyDistance}colors={colors}daysWithData={daysWithData}+ dayDistances={distanceCache.current.get(+ `${mapDate.getFullYear()}-${String(mapDate.getMonth() + 1).padStart(2, "0")}`+ )}onMonthChange={fetchDaysWithData}onPrefetchMonth={prefetchMonth}/>