Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.
Merged
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
74 changes: 34 additions & 40 deletions ecoscan_app/components/alternatives/AlternativesTab.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 (
<>
<FlatList
data={alternatives}
keyExtractor={(item) => item.ean}
renderItem={({ item }) => (
<AlternativeCard
key={item.ean}
name={item.name}
ean={item.ean}
imageUrl={item.imageUrl}
onCopy={() => setIsSnackbarVisible(true)}
<FlatList
data={alternatives}
keyExtractor={(item) => item.ean}
renderItem={({ item }) => (
<AlternativeCard
key={item.ean}
name={item.name}
ean={item.ean}
imageUrl={item.imageUrl}
onCopy={handleCopyEan}
/>
)}
ListEmptyComponent={() =>
loadingEan ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
style={{ padding: 16 }}
/>
)}
ListEmptyComponent={() =>
loadingEan ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
style={{ padding: 16 }}
/>
) : (
<Text style={{ textAlign: "center", color: "gray", padding: 16 }}>
Keine Alternativen gefunden
</Text>
)
}
contentContainerStyle={{ paddingBottom: 8 }}
/>
<Snackbar
visible={isSnackbarVisible}
onDismiss={() => setIsSnackbarVisible(false)}
duration={2000}
style={{ backgroundColor: theme.colors.primary, marginBottom: -16 }}
>
EAN kopiert!
</Snackbar>
</>
) : (
<Text style={{ textAlign: "center", color: "gray", padding: 16 }}>
Keine Alternativen gefunden
</Text>
)
}
contentContainerStyle={{ paddingBottom: 8 }}
/>
);
}
Loading