Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ecoscan_app/app/(tabs)/(scan)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
}
};

Expand Down
19 changes: 9 additions & 10 deletions ecoscan_app/components/product/ProductScreen.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 (
<View style={styles.root}>
Expand Down
15 changes: 0 additions & 15 deletions ecoscan_app/context/ErrorContext.tsx

This file was deleted.

12 changes: 6 additions & 6 deletions ecoscan_app/hooks/useShareScreenshot.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down
Loading