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..20081d22 100644 --- a/ecoscan_app/components/product/ProductScreen.tsx +++ b/ecoscan_app/components/product/ProductScreen.tsx @@ -1,15 +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 { useError } from "@/context/ErrorContext"; -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; @@ -19,21 +19,20 @@ export default function ProductScreen({ showActionButtons = true, }: ProductScreenProps) { const { viewRef, captureAndShare } = useShareScreenshot(); - - const { setError } = useError(); + const { showError } = useSnackbar(); 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 }; -} 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(