From e33decde01f93b6950e049457a722cbeeb1bb7df Mon Sep 17 00:00:00 2001 From: hm-sbartl Date: Mon, 13 Jul 2026 09:30:55 +0200 Subject: [PATCH] :art: unify snackbar and use Context --- .../alternatives/AlternativesTab.tsx | 74 +++++++++---------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/ecoscan_app/components/alternatives/AlternativesTab.tsx b/ecoscan_app/components/alternatives/AlternativesTab.tsx index 4a142ed3..32269c6a 100644 --- a/ecoscan_app/components/alternatives/AlternativesTab.tsx +++ b/ecoscan_app/components/alternatives/AlternativesTab.tsx @@ -1,6 +1,6 @@ -import { useState } from "react"; -import { FlatList, ActivityIndicator, Text } from "react-native"; -import { Snackbar } from "react-native-paper"; +import { ActivityIndicator, FlatList, Text } from "react-native"; +import { useCallback } from "react"; +import { useSnackbar } from "@/context/SnackbarContext"; import AlternativeCard from "@/components/alternatives/AlternativeCard"; import { theme } from "@/theme"; @@ -19,45 +19,39 @@ export default function AlternativesTab({ alternatives, loadingEan, }: AlternativesTabProps) { - const [isSnackbarVisible, setIsSnackbarVisible] = useState(false); + const { showSuccess } = useSnackbar(); + + const handleCopyEan = useCallback(() => { + showSuccess("EAN kopiert!"); + }, [showSuccess]); return ( - <> - item.ean} - renderItem={({ item }) => ( - setIsSnackbarVisible(true)} + item.ean} + renderItem={({ item }) => ( + + )} + ListEmptyComponent={() => + loadingEan ? ( + - )} - ListEmptyComponent={() => - loadingEan ? ( - - ) : ( - - Keine Alternativen gefunden - - ) - } - contentContainerStyle={{ paddingBottom: 8 }} - /> - setIsSnackbarVisible(false)} - duration={2000} - style={{ backgroundColor: theme.colors.primary, marginBottom: -16 }} - > - EAN kopiert! - - + ) : ( + + Keine Alternativen gefunden + + ) + } + contentContainerStyle={{ paddingBottom: 8 }} + /> ); }