From fecddabb918209ea9dd6f9a1ab5c164d7f4db444 Mon Sep 17 00:00:00 2001 From: IamPekka058 <59747867+IamPekka058@users.noreply.github.com> Date: Fri, 10 Jul 2026 16:58:03 +0200 Subject: [PATCH 1/3] :recycle: Refactor error handling to use showError --- ecoscan_app/app/(tabs)/(scan)/index.tsx | 10 +++++----- ecoscan_app/components/product/ProductScreen.tsx | 8 +++----- ecoscan_app/context/ErrorContext.tsx | 15 --------------- 3 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 ecoscan_app/context/ErrorContext.tsx diff --git a/ecoscan_app/app/(tabs)/(scan)/index.tsx b/ecoscan_app/app/(tabs)/(scan)/index.tsx index 84b372b0..0fac58e4 100644 --- a/ecoscan_app/app/(tabs)/(scan)/index.tsx +++ b/ecoscan_app/app/(tabs)/(scan)/index.tsx @@ -14,11 +14,11 @@ import { PageContainer } from "@/components/PageContainer"; import { theme } from "@/theme"; import { useRouter } from "expo-router"; import { useAnalyzeProduct } from "@/hooks/useAnalyzeProduct"; -import { useError } from "@/context/ErrorContext"; +import { useSnackbar } from "@/context/SnackbarContext"; export default function Scan() { const [barcode, setBarcode] = useState(""); - const { setError } = useError(); + const { showError } = useSnackbar(); const router = useRouter(); const { loading, analyzeProduct, cancelAnalysis } = useAnalyzeProduct(); const [scanned, setScanned] = useState(false); @@ -29,7 +29,7 @@ export default function Scan() { setScanned(true); const trimmed = code.trim(); if (!trimmed) { - setError("Barcode darf nicht leer sein."); + showError("Barcode darf nicht leer sein."); return; } try { @@ -40,12 +40,12 @@ export default function Scan() { params: { id: trimmed }, }); } else { - setError("Produkt konnte nicht analysiert werden."); + showError("Produkt konnte nicht analysiert werden."); } } catch (err) { const msg = err instanceof Error ? err.message : "Analyse fehlgeschlagen."; - setError(msg); + showError(msg); } }; diff --git a/ecoscan_app/components/product/ProductScreen.tsx b/ecoscan_app/components/product/ProductScreen.tsx index c37bb443..308159e6 100644 --- a/ecoscan_app/components/product/ProductScreen.tsx +++ b/ecoscan_app/components/product/ProductScreen.tsx @@ -4,7 +4,6 @@ import { useProductData } from "@/hooks/useProductData"; import { router, useLocalSearchParams } from "expo-router"; import React, { useEffect } from "react"; import { ScrollView, StyleSheet, View } from "react-native"; -import { useError } from "@/context/ErrorContext"; import { useShareScreenshot } from "@/hooks/useShareScreenshot"; import ScoreDetailsSkeleton from "@/components/product/loading/ScoreDetailsSkeleton"; import ProductCardSkeleton from "@/components/product/loading/ProductCardSkeleton"; @@ -19,21 +18,20 @@ export default function ProductScreen({ showActionButtons = true, }: ProductScreenProps) { const { viewRef, captureAndShare } = useShareScreenshot(); - - const { setError } = useError(); + const { showError } = useShareScreenshot(); const { id } = useLocalSearchParams(); const { product, productLoading, scoreLoading, error } = useProductData(id); useEffect(() => { if (!error) return; - setError(error); + showError(error); if (router.canGoBack()) { router.back(); } else { router.replace("/(tabs)/(scan)"); } - }, [error, setError]); + }, [error, showError]); return ( diff --git a/ecoscan_app/context/ErrorContext.tsx b/ecoscan_app/context/ErrorContext.tsx deleted file mode 100644 index 95ac1588..00000000 --- a/ecoscan_app/context/ErrorContext.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { useCallback } from "react"; -import { useSnackbar } from "@/context/SnackbarContext"; - -export function useError() { - const { showError } = useSnackbar(); - - const setError = useCallback( - (msg: string, duration?: number) => { - showError(msg, duration ?? 5000); - }, - [showError], - ); - - return { setError }; -} From 19483ffa9de933f961cdfce0fa3a4371325b7b71 Mon Sep 17 00:00:00 2001 From: IamPekka058 <59747867+IamPekka058@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:43:26 +0200 Subject: [PATCH 2/3] :recycle: Refactor useShareScreenshot to improve file handling and cleanup --- ecoscan_app/hooks/useShareScreenshot.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ecoscan_app/hooks/useShareScreenshot.ts b/ecoscan_app/hooks/useShareScreenshot.ts index 26730341..05a990cc 100644 --- a/ecoscan_app/hooks/useShareScreenshot.ts +++ b/ecoscan_app/hooks/useShareScreenshot.ts @@ -1,9 +1,9 @@ +import { useSnackbar } from "@/context/SnackbarContext"; +import { File } from "expo-file-system"; +import * as Sharing from "expo-sharing"; import { useRef, useState } from "react"; import { View } from "react-native"; import { captureRef } from "react-native-view-shot"; -import { useSnackbar } from "@/context/SnackbarContext"; -import * as Sharing from "expo-sharing"; -import { File } from "expo-file-system"; interface ShareOptions { format?: "png" | "jpg" | "webm"; @@ -48,9 +48,9 @@ export function useShareScreenshot({ } finally { if (localUri) { try { - const fileInfo = await FileSystem.getInfoAsync(localUri); - if (fileInfo.exists) { - await FileSystem.deleteAsync(localUri); + const tempFile = new File(localUri); + if (tempFile.exists) { + tempFile.delete(); } } catch (cleanupError) { console.warn( From 494c14a437ebafdcb87ed94f95b8d01a1c67f087 Mon Sep 17 00:00:00 2001 From: IamPekka058 <59747867+IamPekka058@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:43:45 +0200 Subject: [PATCH 3/3] :bug: Fix wrong hook call --- ecoscan_app/components/product/ProductScreen.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ecoscan_app/components/product/ProductScreen.tsx b/ecoscan_app/components/product/ProductScreen.tsx index 308159e6..20081d22 100644 --- a/ecoscan_app/components/product/ProductScreen.tsx +++ b/ecoscan_app/components/product/ProductScreen.tsx @@ -1,14 +1,15 @@ import { PageContainer } from "@/components/PageContainer"; +import ProductCardSkeleton from "@/components/product/loading/ProductCardSkeleton"; +import ScoreDetailsSkeleton from "@/components/product/loading/ScoreDetailsSkeleton"; +import ProductScoreDashboard from "@/components/product/ProductScoreDashboard"; import ProductCard from "@/components/product/sections/ProductCard"; +import ShareComponent from "@/components/product/ShareComponent"; +import { useSnackbar } from "@/context/SnackbarContext"; import { useProductData } from "@/hooks/useProductData"; +import { useShareScreenshot } from "@/hooks/useShareScreenshot"; import { router, useLocalSearchParams } from "expo-router"; import React, { useEffect } from "react"; import { ScrollView, StyleSheet, View } from "react-native"; -import { useShareScreenshot } from "@/hooks/useShareScreenshot"; -import ScoreDetailsSkeleton from "@/components/product/loading/ScoreDetailsSkeleton"; -import ProductCardSkeleton from "@/components/product/loading/ProductCardSkeleton"; -import ProductScoreDashboard from "@/components/product/ProductScoreDashboard"; -import ShareComponent from "@/components/product/ShareComponent"; type ProductScreenProps = { showActionButtons?: boolean; @@ -18,7 +19,7 @@ export default function ProductScreen({ showActionButtons = true, }: ProductScreenProps) { const { viewRef, captureAndShare } = useShareScreenshot(); - const { showError } = useShareScreenshot(); + const { showError } = useSnackbar(); const { id } = useLocalSearchParams(); const { product, productLoading, scoreLoading, error } = useProductData(id);