Files
Shoppy/src/components/product/ProductCard.js
T
Fretux ab963d8421
Android Release Build / build-android (push) Failing after 7m42s
improve product search and barcode scanning
2026-11-20 00:51:47 +01:00

113 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Pressable, StyleSheet, Text, View } from 'react-native';
import { colors } from '../../utils/constants';
import ProductImage from './ProductImage';
import ProductScoreBadge from './ProductScoreBadge';
export default function ProductCard({ product, rating, onPress, searchMetadata }) {
return (
<Pressable accessibilityRole="button" onPress={onPress} style={styles.card}>
<View style={styles.topRow}>
<ProductImage imageUrl={product.imageUrl} productName={product.name} />
<View style={styles.copy}>
<Text style={styles.name}>{product.name}</Text>
<Text style={styles.meta}>
{product.brand || 'Ohne Marke'}
</Text>
<Text style={styles.note}>
{product.category || 'Produkt'} · Barcode {product.barcode}
</Text>
<Text style={styles.source}>{sourceLabel(product.dataSource)}</Text>
</View>
</View>
<View style={styles.footer}>
{rating ? <ProductScoreBadge status={rating.overallStatus} score={rating.overallScore} /> : null}
<Text style={styles.openLabel}>Details ansehen ›</Text>
</View>
{searchMetadata ? (
<View style={styles.searchMeta}>
<Text style={styles.matchLabel}>{searchMetadata.matchLabel}</Text>
<Text style={styles.coverageLabel}>
{searchMetadata.dataCoverage}% Produktdaten · {searchMetadata.freshnessLabel}
</Text>
</View>
) : null}
{rating?.allergenReviewRequired ? <Text style={styles.allergenWarning}>{rating.allergenReviewMessage}</Text> : null}
{rating?.staleDataReviewRequired ? <Text style={styles.allergenWarning}>Gespeicherte Produktdaten sind veraltet.</Text> : null}
</Pressable>
);
}
function sourceLabel(source) {
const labels = {
cache: 'Lokaler Cache',
local: 'Lokal erfasst',
'open-food-facts': 'Open Food Facts'
};
return labels[source] || 'Quelle unbekannt';
}
const styles = StyleSheet.create({
card: {
backgroundColor: colors.surface,
borderColor: colors.border,
borderRadius: 18,
borderWidth: 1,
gap: 10,
padding: 16
},
topRow: {
alignItems: 'flex-start',
flexDirection: 'row',
gap: 12
},
footer: {
alignItems: 'center',
borderTopColor: colors.border,
borderTopWidth: 1,
flexDirection: 'row',
justifyContent: 'space-between',
paddingTop: 11
},
openLabel: {
color: colors.primary,
fontSize: 13,
fontWeight: '800'
},
copy: {
flex: 1
},
name: {
color: colors.text,
fontSize: 16,
fontWeight: '800'
},
meta: {
color: colors.muted,
fontSize: 14,
marginTop: 4
},
note: {
color: colors.muted,
fontSize: 13,
lineHeight: 18,
marginTop: 5
},
source: {
alignSelf: 'flex-start',
backgroundColor: colors.surfaceTint,
borderRadius: 8,
color: colors.primaryDark,
fontSize: 12,
fontWeight: '800',
marginTop: 8,
paddingHorizontal: 8,
paddingVertical: 4
},
allergenWarning: { color: colors.danger, fontSize: 14, fontWeight: '800' },
searchMeta: { backgroundColor: colors.background, borderRadius: 10, gap: 3, padding: 10 },
matchLabel: { color: colors.primaryDark, fontSize: 12, fontWeight: '800' },
coverageLabel: { color: colors.muted, fontSize: 12, lineHeight: 17 }
});