add features for manual product editing
Android Release Build / build-android (push) Failing after 7m11s
Android Release Build / build-android (push) Failing after 7m11s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Alert, Platform, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
||||
import { Alert, Linking, Platform, Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
||||
|
||||
import PrimaryButton from '../components/PrimaryButton';
|
||||
import SecondaryButton from '../components/SecondaryButton';
|
||||
@@ -20,6 +20,7 @@ export default function ProductDetailScreen({
|
||||
onAddToList,
|
||||
onOpenList,
|
||||
onSaveManualPrice,
|
||||
onEditProduct,
|
||||
onShowRatingCriteria,
|
||||
onShowAlternatives,
|
||||
shoppingList
|
||||
@@ -37,6 +38,7 @@ export default function ProductDetailScreen({
|
||||
}), [currency, hasProductPrice, parsedManualPrice, product]);
|
||||
const rating = useMemo(() => calculateProductRating(pricedProduct, preferences, { shoppingList }), [pricedProduct, preferences, shoppingList]);
|
||||
const footprint = product.sustainability?.footprint;
|
||||
const missingFields = missingProductFields(product, preferences);
|
||||
const recommendation = rating.overallStatus === 'good' ? 'Passt gut zu dir'
|
||||
: rating.overallStatus === 'critical' ? 'Lieber meiden'
|
||||
: rating.overallStatus === 'unknown' ? 'Zu wenig Daten' : 'Genauer prüfen';
|
||||
@@ -93,6 +95,8 @@ export default function ProductDetailScreen({
|
||||
{product.category || 'Produkt'} · {formatPrice(pricedProduct.price, currency)}
|
||||
</Text>
|
||||
<Text style={styles.source}>{sourceLabel(product.dataSource)}{product.cacheStale ? ' · Veraltete Daten' : ''}</Text>
|
||||
{product.manualOverrides ? <Text style={styles.meta}>Angaben von dir ergänzt · lokal gespeichert</Text> : null}
|
||||
{product.manualOverrides ? <Text style={styles.meta}>Etikettangaben: {manualFieldNames(product.manualOverrides).join(', ') || 'Produkttyp'}</Text> : null}
|
||||
{['cache', 'open-food-facts'].includes(product.dataSource) ? <Text style={styles.meta}>Produktdaten geprüft: {formatCheckedDate(product.fetchedAt)}</Text> : null}
|
||||
</View>
|
||||
<ProductScoreBadge status={rating.overallStatus} score={rating.overallScore} />
|
||||
@@ -118,6 +122,20 @@ export default function ProductDetailScreen({
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
<View style={styles.dataPanel}>
|
||||
<Text style={styles.factorTitle}>Produktangaben ergänzen</Text>
|
||||
<Text style={styles.dataText}>{missingFields.length
|
||||
? `Für eine genauere Bewertung fehlen: ${missingFields.join(', ')}.`
|
||||
: 'Die wichtigsten Angaben für die Bewertung sind vorhanden.'}</Text>
|
||||
<Text style={styles.dataText}>Übertrage Werte von der Verpackung. Fehlende Werte werden nicht geschätzt.</Text>
|
||||
<SecondaryButton label="Angaben ergänzen oder korrigieren" onPress={() => onEditProduct(product)} />
|
||||
{/^\d{8,14}$/.test(product.barcode || '') ? (
|
||||
<Pressable accessibilityRole="link" onPress={() => Linking.openURL(`https://world.openfoodfacts.org/product/${product.barcode}`)}>
|
||||
<Text style={styles.savedLink}>Produkt auf Open Food Facts öffnen ›</Text>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{!hasProductPrice ? (
|
||||
<View style={styles.pricePanel}>
|
||||
<Text style={styles.priceTitle}>Ladenpreis ergänzen</Text>
|
||||
@@ -233,6 +251,38 @@ function recommendationMessage(rating) {
|
||||
return 'Tippe unten auf ein Kriterium, um die Bewertung nachzuvollziehen.';
|
||||
}
|
||||
|
||||
function missingProductFields(product, preferences) {
|
||||
const nutrition = product.nutrition || {};
|
||||
const fields = [];
|
||||
const beverage = product.categoryTags?.includes('en:beverages') || product.dataSource === 'local';
|
||||
if (product.dataCompleteness?.name === false) fields.push('Produktname');
|
||||
if (!product.categoryTags?.length) fields.push('Produkttyp');
|
||||
if (!product.dataCompleteness?.ingredients) fields.push('Zutatenliste');
|
||||
if (preferences.avoidAllergens?.length && !product.dataCompleteness?.allergens) fields.push('Allergenangaben');
|
||||
if (!Number.isFinite(nutrition.sugarPer100g)) fields.push(`Zucker pro ${beverage ? '100 ml' : '100 g'}`);
|
||||
if (beverage && !nutrition.nutriScore) {
|
||||
if (!Number.isFinite(nutrition.energyKjPer100g) && !Number.isFinite(nutrition.caloriesPer100g)) fields.push('Energie');
|
||||
if (!Number.isFinite(nutrition.saturatedFatPer100g)) fields.push('gesättigte Fettsäuren');
|
||||
if (!Number.isFinite(nutrition.saltPer100g)) fields.push('Salz');
|
||||
if (typeof nutrition.hasNonNutritiveSweeteners !== 'boolean') fields.push('Süssstoffe');
|
||||
}
|
||||
if (typeof product.price !== 'number' && Number.isFinite(preferences.maxBudgetPerShoppingTrip)) fields.push('Preis');
|
||||
return fields.slice(0, 6);
|
||||
}
|
||||
|
||||
function manualFieldNames(overrides) {
|
||||
const names = { name: 'Name', brand: 'Marke', ingredients: 'Zutaten',
|
||||
allergens: 'Allergene', allergenTraces: 'Spuren', drinkType: 'Produkttyp' };
|
||||
return [
|
||||
...Object.keys(overrides).filter((key) => key !== 'nutrition').map((key) => names[key]).filter(Boolean),
|
||||
...Object.keys(overrides.nutrition || {}).map((key) =>
|
||||
({ energyKjPer100g: 'Energie', sugarPer100g: 'Zucker', saturatedFatPer100g: 'gesättigte Fettsäuren',
|
||||
saltPer100g: 'Salz', proteinPer100g: 'Protein', fiberPer100g: 'Ballaststoffe',
|
||||
fruitVegetableLegumePercent: 'Frucht- und Gemüseanteil', hasNonNutritiveSweeteners: 'Süssstoffe' })[key]
|
||||
).filter(Boolean)
|
||||
];
|
||||
}
|
||||
|
||||
function parseManualPrice(value) {
|
||||
const normalizedValue = value.trim().replace(',', '.');
|
||||
const parsedValue = Number(normalizedValue);
|
||||
@@ -247,7 +297,7 @@ function parseManualPrice(value) {
|
||||
function sourceLabel(source) {
|
||||
const labels = {
|
||||
cache: 'Quelle: lokaler Cache',
|
||||
local: 'Quelle: lokale Beispieldaten',
|
||||
local: 'Quelle: lokal erfasst',
|
||||
'open-food-facts': 'Quelle: Open Food Facts'
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user