This commit is contained in:
@@ -7,6 +7,7 @@ import AlternativesScreen from './src/screens/AlternativesScreen';
|
||||
import HomeScreen from './src/screens/HomeScreen';
|
||||
import ProductDetailScreen from './src/screens/ProductDetailScreen';
|
||||
import ProfileScreen from './src/screens/ProfileScreen';
|
||||
import PrivacyScreen from './src/screens/PrivacyScreen';
|
||||
import RatingCriteriaDetailScreen from './src/screens/RatingCriteriaDetailScreen';
|
||||
import ScanScreen from './src/screens/ScanScreen';
|
||||
import ShoppingListScreen from './src/screens/ShoppingListScreen';
|
||||
@@ -35,6 +36,7 @@ export default function App() {
|
||||
const [lastDeletedListItem, setLastDeletedListItem] = useState(null);
|
||||
const [isHydrated, setIsHydrated] = useState(false);
|
||||
const [storageError, setStorageError] = useState('');
|
||||
const [isClearingProductData, setIsClearingProductData] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
@@ -150,7 +152,10 @@ export default function App() {
|
||||
if (activeTab === 'profile') {
|
||||
return (
|
||||
<ProfileScreen
|
||||
isClearingProductData={isClearingProductData}
|
||||
onChangePreferences={setPreferences}
|
||||
onClearProductData={clearProductHistoryAndCache}
|
||||
onOpenPrivacy={() => setRoute({ name: 'privacy' })}
|
||||
preferences={preferences}
|
||||
/>
|
||||
);
|
||||
@@ -166,7 +171,22 @@ export default function App() {
|
||||
shoppingList={shoppingList}
|
||||
/>
|
||||
);
|
||||
}, [activeTab, lastDeletedListItem, manualPrices, preferences, productCache, recentProducts, shoppingList]);
|
||||
}, [activeTab, isClearingProductData, lastDeletedListItem, manualPrices, preferences, productCache, recentProducts, shoppingList]);
|
||||
|
||||
async function clearProductHistoryAndCache() {
|
||||
if (isClearingProductData) return;
|
||||
setIsClearingProductData(true);
|
||||
try {
|
||||
await storageService.clearProductHistoryAndCache();
|
||||
setProductCache({});
|
||||
setRecentProducts([]);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
} finally {
|
||||
setIsClearingProductData(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function scanProductByBarcode(barcode) {
|
||||
const result = await lookupProductByBarcode(
|
||||
@@ -388,6 +408,11 @@ export default function App() {
|
||||
}
|
||||
|
||||
function goBackFromRoute() {
|
||||
if (route.name === 'privacy') {
|
||||
setRoute({ name: 'tabs' });
|
||||
return true;
|
||||
}
|
||||
|
||||
if (route.name === 'ratingCriteria' && routeProduct) {
|
||||
setRoute({ name: 'productDetail', product: routeProduct });
|
||||
return true;
|
||||
@@ -416,6 +441,10 @@ export default function App() {
|
||||
);
|
||||
}
|
||||
|
||||
if (route.name === 'privacy') {
|
||||
return <PrivacyScreen onBack={goBackToTabs} />;
|
||||
}
|
||||
|
||||
if (route.name === 'productDetail' && routeProduct) {
|
||||
return (
|
||||
<ProductDetailScreen
|
||||
|
||||
@@ -25,6 +25,7 @@ export default function ProductCard({ product, rating, onPress }) {
|
||||
{rating ? <ProductScoreBadge status={rating.overallStatus} score={rating.overallScore} /> : null}
|
||||
<Text style={styles.openLabel}>Details ansehen ›</Text>
|
||||
</View>
|
||||
{rating?.allergenReviewRequired ? <Text style={styles.allergenWarning}>Allergenangaben fehlen – Verpackung prüfen.</Text> : null}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
@@ -95,5 +96,6 @@ const styles = StyleSheet.create({
|
||||
marginTop: 8,
|
||||
paddingHorizontal: 8,
|
||||
paddingVertical: 4
|
||||
}
|
||||
},
|
||||
allergenWarning: { color: colors.danger, fontSize: 14, fontWeight: '800' }
|
||||
});
|
||||
|
||||
@@ -72,7 +72,11 @@ export default function ProductDetailScreen({
|
||||
</View>
|
||||
<View style={[styles.recommendation, styles[`${rating.overallStatus}Recommendation`]]}>
|
||||
<Text style={[styles.recommendationTitle, styles[`${rating.overallStatus}Text`]]}>{recommendation}</Text>
|
||||
<Text style={styles.recommendationCopy}>Tippe unten auf ein Kriterium, um die Bewertung nachzuvollziehen.</Text>
|
||||
<Text style={styles.recommendationCopy}>
|
||||
{rating.allergenReviewRequired
|
||||
? 'Allergenangaben fehlen oder sind nicht bestätigt. Prüfe vor dem Kauf die Verpackung.'
|
||||
: 'Tippe unten auf ein Kriterium, um die Bewertung nachzuvollziehen.'}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
||||
import { useState } from 'react';
|
||||
import { Alert, Platform, Pressable, StyleSheet, Text, View } from 'react-native';
|
||||
|
||||
import BudgetInput from '../components/form/BudgetInput';
|
||||
import SettingsSwitchRow from '../components/form/SettingsSwitchRow';
|
||||
@@ -12,7 +13,32 @@ const allergenOptions = ['Erdnüsse', 'Milch', 'Hafer', 'Gluten'];
|
||||
const priorityOptions = ['low', 'medium', 'high'];
|
||||
const priorityLabels = { low: 'Niedrig', medium: 'Mittel', high: 'Hoch' };
|
||||
|
||||
export default function ProfileScreen({ preferences, onChangePreferences }) {
|
||||
export default function ProfileScreen({ preferences, onChangePreferences, onOpenPrivacy, onClearProductData, isClearingProductData }) {
|
||||
const [dataMessage, setDataMessage] = useState('');
|
||||
|
||||
async function clearProductData() {
|
||||
const success = await onClearProductData();
|
||||
setDataMessage(success
|
||||
? 'Verlauf und Produktcache wurden gelöscht.'
|
||||
: 'Die Daten konnten nicht gelöscht werden. Bitte versuche es erneut.');
|
||||
}
|
||||
|
||||
function confirmClearProductData() {
|
||||
const message = 'Gespeicherte Produkte und letzte Scans werden entfernt. Einkaufsliste, Einstellungen und manuelle Preise bleiben erhalten.';
|
||||
if (Platform.OS === 'web') {
|
||||
if (window.confirm(`Verlauf und Produktcache löschen?\n\n${message}`)) clearProductData();
|
||||
return;
|
||||
}
|
||||
Alert.alert(
|
||||
'Verlauf und Produktcache löschen?',
|
||||
message,
|
||||
[
|
||||
{ text: 'Abbrechen', style: 'cancel' },
|
||||
{ text: 'Löschen', style: 'destructive', onPress: clearProductData }
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
function updatePreference(key, value) {
|
||||
onChangePreferences({ ...preferences, [key]: value });
|
||||
}
|
||||
@@ -116,6 +142,22 @@ export default function ProfileScreen({ preferences, onChangePreferences }) {
|
||||
onValueChange={(value) => updatePreference('offlineModeEnabled', value)}
|
||||
value={preferences.offlineModeEnabled}
|
||||
/>
|
||||
<View style={styles.divider} />
|
||||
<Pressable accessibilityRole="link" onPress={onOpenPrivacy} style={styles.dataAction}>
|
||||
<Text style={styles.dataActionText}>Datenschutzerklärung ansehen ›</Text>
|
||||
</Pressable>
|
||||
<View style={styles.divider} />
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ disabled: isClearingProductData }}
|
||||
disabled={isClearingProductData}
|
||||
onPress={confirmClearProductData}
|
||||
style={styles.dataAction}
|
||||
>
|
||||
<Text style={styles.deleteActionText}>{isClearingProductData ? 'Daten werden gelöscht...' : 'Verlauf und Produktcache löschen'}</Text>
|
||||
</Pressable>
|
||||
<Text style={styles.fieldHint}>Einkaufsliste, Einstellungen und manuelle Preise bleiben erhalten.</Text>
|
||||
{dataMessage ? <Text accessibilityRole="alert" style={styles.fieldHint}>{dataMessage}</Text> : null}
|
||||
</SettingsSection>
|
||||
</ScreenContainer>
|
||||
);
|
||||
@@ -263,5 +305,8 @@ const styles = StyleSheet.create({
|
||||
justifyContent: 'center',
|
||||
minHeight: 44,
|
||||
paddingHorizontal: 4
|
||||
}
|
||||
},
|
||||
dataAction: { justifyContent: 'center', minHeight: 44 },
|
||||
dataActionText: { color: colors.primary, fontSize: 15, fontWeight: '800' },
|
||||
deleteActionText: { color: colors.danger, fontSize: 15, fontWeight: '800' }
|
||||
});
|
||||
|
||||
@@ -122,10 +122,14 @@ export function calculateProductRating(product, preferences) {
|
||||
|
||||
const weights = ratingWeights(preferences);
|
||||
const hasBlockedAllergen = categoryScores.allergies.score === 0;
|
||||
const allergenReviewRequired = categoryScores.allergies.needsReview === true;
|
||||
const criticalAdditiveCount = categoryScores.ingredients.criticalAdditiveCount || 0;
|
||||
const overallScore = hasBlockedAllergen
|
||||
? 0
|
||||
: capOverallScoreForCriticalAdditives(weightedCategoryScore(categoryScores, weights), criticalAdditiveCount);
|
||||
: Math.min(
|
||||
capOverallScoreForCriticalAdditives(weightedCategoryScore(categoryScores, weights), criticalAdditiveCount),
|
||||
allergenReviewRequired ? 77 : 100
|
||||
);
|
||||
const overallStatus = statusFromScore(overallScore);
|
||||
|
||||
const reasons = Object.entries(categoryScores).map(([category, value]) => ({
|
||||
@@ -138,6 +142,7 @@ export function calculateProductRating(product, preferences) {
|
||||
productId: product.id,
|
||||
overallStatus,
|
||||
overallScore,
|
||||
allergenReviewRequired,
|
||||
reasons,
|
||||
categoryScores
|
||||
};
|
||||
@@ -190,15 +195,20 @@ function rateAllergies(product, preferences) {
|
||||
avoidAllergens.some((blockedAllergen) => blockedAllergen.toLowerCase() === allergen.toLowerCase())
|
||||
);
|
||||
const completeness = product.dataCompleteness || {};
|
||||
const allergenDataMissing = completeness.allergens !== true || !Array.isArray(product.allergens) || product.allergens.length === 0;
|
||||
const missingData = missingMessages([
|
||||
[completeness.allergens === false, 'Allergenangaben fehlen in Open Food Facts.']
|
||||
[avoidAllergens.length > 0 && allergenDataMissing, 'Allergenangaben fehlen oder sind nicht bestätigt. Verpackung prüfen.']
|
||||
]);
|
||||
|
||||
if (matchingAllergens.length > 0) {
|
||||
return withScore(0, `Enthält: ${matchingAllergens.join(', ')}.`, missingData);
|
||||
}
|
||||
|
||||
return withScore(completeness.allergens === false ? 70 : 100, 'Keine hinterlegten Allergene gefunden.', missingData);
|
||||
if (avoidAllergens.length > 0 && allergenDataMissing) {
|
||||
return withScore(50, 'Allergenangaben fehlen – Verpackung prüfen.', missingData, { needsReview: true });
|
||||
}
|
||||
|
||||
return withScore(100, 'Keine hinterlegten Allergene gefunden.', missingData);
|
||||
}
|
||||
|
||||
function rateIngredients(product, preferences) {
|
||||
|
||||
@@ -9,6 +9,13 @@ const keys = {
|
||||
};
|
||||
|
||||
const legacyPrefix = 'shoppy.';
|
||||
let pendingWrite = Promise.resolve();
|
||||
|
||||
function enqueueWrite(operation) {
|
||||
const result = pendingWrite.then(operation);
|
||||
pendingWrite = result.catch(() => {});
|
||||
return result;
|
||||
}
|
||||
|
||||
async function readJson(key, fallbackValue) {
|
||||
try {
|
||||
@@ -31,7 +38,7 @@ async function readJson(key, fallbackValue) {
|
||||
|
||||
async function writeJson(key, value) {
|
||||
try {
|
||||
await AsyncStorage.setItem(key, JSON.stringify(value));
|
||||
await enqueueWrite(() => AsyncStorage.setItem(key, JSON.stringify(value)));
|
||||
} catch (error) {
|
||||
// Storage is best-effort; the in-memory state remains usable.
|
||||
console.warn(`Shoppinguin konnte ${key} nicht speichern.`, error);
|
||||
@@ -48,5 +55,11 @@ export const storageService = {
|
||||
loadManualPrices: () => readJson(keys.manualPrices, {}),
|
||||
saveManualPrices: (prices) => writeJson(keys.manualPrices, prices),
|
||||
loadRecentProducts: () => readJson(keys.recentProducts, []),
|
||||
saveRecentProducts: (products) => writeJson(keys.recentProducts, products)
|
||||
saveRecentProducts: (products) => writeJson(keys.recentProducts, products),
|
||||
clearProductHistoryAndCache: () => enqueueWrite(() => AsyncStorage.multiRemove([
|
||||
keys.productCache,
|
||||
keys.recentProducts,
|
||||
keys.productCache.replace(/^shoppinguin\./, legacyPrefix),
|
||||
keys.recentProducts.replace(/^shoppinguin\./, legacyPrefix)
|
||||
]))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user