Colota - Android GPS Location tracker
feat: add themed error boundary component
Max Dietrichf022e61e3c3e
diff --git a/App.tsx b/App.tsxindex 66c1ec67..469603da 100644--- a/App.tsx+++ b/App.tsx@@ -2,7 +2,6 @@* Copyright (C) 2026 Max Dietrich* Licensed under the GNU AGPLv3. See LICENSE in the project root for details.*/-import React, { useMemo } from "react";import { NavigationContainer } from "@react-navigation/native";import { createNativeStackNavigator } from "@react-navigation/native-stack";@@ -10,6 +9,7 @@ import { SafeAreaProvider } from "react-native-safe-area-context";import { StatusBar, Platform } from "react-native";import { ThemeProvider, useTheme } from "./src/hooks/useTheme";import { TrackingProvider } from "./src/contexts/TrackingProvider";+import ThemedErrorBoundary from "./src/components/ThemedErrorBoundary";import {DashboardScreen,SettingsScreen,@@ -68,7 +68,6 @@ const SCREEN_CONFIG = [function AppNavigator() {const { colors, isDark } = useTheme();-const screenOptions = useMemo(() => ({headerStyle: {@@ -90,10 +89,8 @@ function AppNavigator() {}),[colors]);-const statusBarConfig = useMemo(() => ({- // Dark mode: white icons, Light mode: dark iconsbarStyle: isDark ? ("light-content" as const) : ("dark-content" as const),backgroundColor: colors.background,translucent: false,@@ -101,7 +98,6 @@ function AppNavigator() {}),[colors.background, isDark]);-return (<SafeAreaProvider><StatusBar {...statusBarConfig} />@@ -127,9 +123,11 @@ function AppNavigator() {export default function App() {return (<ThemeProvider>- <TrackingProvider>- <AppNavigator />- </TrackingProvider>+ <ThemedErrorBoundary>+ <TrackingProvider>+ <AppNavigator />+ </TrackingProvider>+ </ThemedErrorBoundary></ThemeProvider>);}diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsxnew file mode 100644index 00000000..33b87b31--- /dev/null+++ b/src/components/ErrorBoundary.tsx@@ -0,0 +1,102 @@+/**+ * Copyright (C) 2026 Max Dietrich+ * Licensed under the GNU AGPLv3. See LICENSE in the project root for details.+ */+import React, { Component } from "react";+import { View, Text, StyleSheet, TouchableOpacity } from "react-native";+import { ThemeColors } from "../types/global";++interface ErrorBoundaryProps {+ children: React.ReactNode;+ colors: ThemeColors;+}++interface ErrorBoundaryState {+ hasError: boolean;+ error: Error | null;+}++class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {+ constructor(props: ErrorBoundaryProps) {+ super(props);+ this.state = { hasError: false, error: null };+ }++ static getDerivedStateFromError(error: Error): ErrorBoundaryState {+ return { hasError: true, error };+ }++ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {+ // Log to error reporting service (e.g., Sentry, Crashlytics)+ console.error("ErrorBoundary caught an error:", error, errorInfo);++ // You can add error tracking here:+ // Sentry.captureException(error);+ }++ handleReset = () => {+ this.setState({ hasError: false, error: null });+ };++ render() {+ const { colors, children } = this.props;++ if (this.state.hasError) {+ return (+ <View+ style={[+ styles.errorContainer,+ { backgroundColor: colors.background },+ ]}+ >+ <Text style={[styles.errorTitle, { color: colors.text }]}>+ Something went wrong+ </Text>+ <Text style={[styles.errorMessage, { color: colors.textSecondary }]}>+ {this.state.error?.message || "An unexpected error occurred"}+ </Text>+ <TouchableOpacity+ style={[styles.errorButton, { backgroundColor: colors.primary }]}+ onPress={this.handleReset}+ >+ <Text style={styles.errorButtonText}>Try Again</Text>+ </TouchableOpacity>+ </View>+ );+ }++ return children;+ }+}++const styles = StyleSheet.create({+ errorContainer: {+ flex: 1,+ justifyContent: "center",+ alignItems: "center",+ padding: 20,+ },+ errorTitle: {+ fontSize: 24,+ fontWeight: "bold",+ marginBottom: 10,+ },+ errorMessage: {+ fontSize: 16,+ textAlign: "center",+ marginBottom: 20,+ paddingHorizontal: 20,+ },+ errorButton: {+ paddingHorizontal: 24,+ paddingVertical: 12,+ borderRadius: 8,+ },+ errorButtonText: {+ fontSize: 16,+ color: "#fff",+ fontWeight: "600",+ },+});++export default ErrorBoundary;diff --git a/src/components/ThemedErrorBoundary.tsx b/src/components/ThemedErrorBoundary.tsxnew file mode 100644index 00000000..c2c06583--- /dev/null+++ b/src/components/ThemedErrorBoundary.tsx@@ -0,0 +1,21 @@+/**+ * Copyright (C) 2026 Max Dietrich+ * Licensed under the GNU AGPLv3. See LICENSE in the project root for details.+ */+import React from "react";+import { useTheme } from "../hooks/useTheme";+import ErrorBoundary from "./ErrorBoundary";++interface ThemedErrorBoundaryProps {+ children: React.ReactNode;+}++const ThemedErrorBoundary: React.FC<ThemedErrorBoundaryProps> = ({+ children,+}) => {+ const { colors } = useTheme();++ return <ErrorBoundary colors={colors}>{children}</ErrorBoundary>;+};++export default ThemedErrorBoundary;diff --git a/src/components/features/dashboard/CoordinateDisplay.tsx b/src/components/features/dashboard/CoordinateDisplay.tsxindex 5e72b829..9fc0d953 100644--- a/src/components/features/dashboard/CoordinateDisplay.tsx+++ b/src/components/features/dashboard/CoordinateDisplay.tsx@@ -25,8 +25,6 @@ type Props = {* - Latitude/Longitude (6 decimal places)* - Altitude (rounded meters)* - Accuracy (1 decimal place, with ± prefix)- * - Speed (1 decimal place, m/s)- * - Bearing (degrees)** All values include fallbacks for missing data and adapt to the current theme.*@@ -37,9 +35,7 @@ type Props = {* latitude: 37.7749,* longitude: -122.4194,* altitude: 52,- * accuracy: 10.5,- * speed: 1.2,- * bearing: 180+ * accuracy: 10.5* }}* />* ```@@ -52,8 +48,6 @@ export function CoordinateDisplay({ coords }: Props) {const longitude = coords.longitude?.toFixed(6) ?? "0.000000";const altitude = Math.round(coords.altitude ?? 0);const accuracy = coords.accuracy?.toFixed(1) ?? "0.0";- const speed = coords.speed?.toFixed(1) ?? "0.0";- const bearing = coords.bearing?.toFixed(0) ?? "0";/*** Renders a single coordinate metric card@@ -85,12 +79,6 @@ export function CoordinateDisplay({ coords }: Props) {{renderCard("Altitude", altitude.toLocaleString(), "m")}{renderCard("Accuracy", `±${accuracy}`, "m")}</View>-- {/* Third Row: Speed and Bearing */}- <View style={styles.row}>- {renderCard("Speed", speed, "m/s")}- {renderCard("Bearing", bearing, "°")}- </View></View></>);diff --git a/src/screens/LocationInspectorScreen.tsx b/src/screens/LocationInspectorScreen.tsxindex c176f443..4b7ef7ff 100644--- a/src/screens/LocationInspectorScreen.tsx+++ b/src/screens/LocationInspectorScreen.tsx@@ -84,7 +84,7 @@ const LocationItem = memo(({ item, colors, isQueue }: LocationItemProps) => {#{item.id || item.location_id}</Text><Text style={[styles.time, { color: colors.textSecondary }]}>- {new Date(timestamp).toLocaleTimeString()}+ {new Date(timestamp * 1000).toLocaleTimeString()}</Text></View>