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:
@@ -6,6 +6,7 @@ import BottomTabBar from './src/components/layout/BottomTabBar';
|
||||
import AlternativesScreen from './src/screens/AlternativesScreen';
|
||||
import HomeScreen from './src/screens/HomeScreen';
|
||||
import ProductDetailScreen from './src/screens/ProductDetailScreen';
|
||||
import ProductEditScreen from './src/screens/ProductEditScreen';
|
||||
import ProfileScreen from './src/screens/ProfileScreen';
|
||||
import PrivacyScreen from './src/screens/PrivacyScreen';
|
||||
import RatingCriteriaDetailScreen from './src/screens/RatingCriteriaDetailScreen';
|
||||
@@ -13,6 +14,7 @@ import ScanScreen from './src/screens/ScanScreen';
|
||||
import ShoppingListScreen from './src/screens/ShoppingListScreen';
|
||||
import { lookupProductByBarcode } from './src/services/productApi';
|
||||
import { enrichEnvironmentalProduct } from './src/services/environmentalService';
|
||||
import { createLocalProduct, saveManualProduct } from './src/services/manualProduct';
|
||||
import { storageService } from './src/services/storageService';
|
||||
import { colors, defaultPreferences } from './src/utils/constants';
|
||||
|
||||
@@ -124,6 +126,7 @@ export default function App() {
|
||||
if (activeTab === 'scan') {
|
||||
return (
|
||||
<ScanScreen
|
||||
onCreateLocalProduct={startLocalProduct}
|
||||
onOpenProduct={openProduct}
|
||||
onScanBarcode={scanProductByBarcode}
|
||||
preferences={preferences}
|
||||
@@ -212,6 +215,28 @@ export default function App() {
|
||||
setRoute({ name: 'productDetail', product: pricedProduct });
|
||||
}
|
||||
|
||||
function startLocalProduct(barcode) {
|
||||
setRoute({ name: 'productEdit', product: createLocalProduct(barcode), isNew: true });
|
||||
}
|
||||
|
||||
function editProduct(product) {
|
||||
setRoute({ name: 'productEdit', product, isNew: false });
|
||||
}
|
||||
|
||||
function saveProductEdits(changes) {
|
||||
const updated = saveManualProduct(route.product, changes);
|
||||
setProductCache((current) => ({ ...current, [updated.barcode]: updated }));
|
||||
setRecentProducts((current) => current.map((item) =>
|
||||
item.barcode === updated.barcode ? { ...item, ...updated } : item
|
||||
));
|
||||
setShoppingList((current) => ({
|
||||
...current,
|
||||
items: current.items.map((item) => item.barcode === updated.barcode
|
||||
? { ...item, productName: updated.name, nutrition: updated.nutrition } : item)
|
||||
}));
|
||||
setRoute({ name: 'productDetail', product: updated });
|
||||
}
|
||||
|
||||
function showAlternatives(product) {
|
||||
setRoute({ name: 'alternatives', product });
|
||||
}
|
||||
@@ -410,6 +435,10 @@ export default function App() {
|
||||
}
|
||||
|
||||
function goBackFromRoute() {
|
||||
if (route.name === 'productEdit' && routeProduct) {
|
||||
setRoute(route.isNew ? { name: 'tabs' } : { name: 'productDetail', product: routeProduct });
|
||||
return true;
|
||||
}
|
||||
if (route.name === 'privacy') {
|
||||
setRoute({ name: 'tabs' });
|
||||
return true;
|
||||
@@ -447,10 +476,16 @@ export default function App() {
|
||||
return <PrivacyScreen onBack={goBackToTabs} />;
|
||||
}
|
||||
|
||||
if (route.name === 'productEdit' && routeProduct) {
|
||||
return <ProductEditScreen key={routeProduct.id} product={routeProduct} isNew={route.isNew}
|
||||
onBack={goBackFromRoute} onSave={saveProductEdits} />;
|
||||
}
|
||||
|
||||
if (route.name === 'productDetail' && routeProduct) {
|
||||
return (
|
||||
<ProductDetailScreen
|
||||
onAddToList={addProductToShoppingList}
|
||||
onEditProduct={editProduct}
|
||||
onBack={goBackToTabs}
|
||||
onOpenList={() => {
|
||||
setActiveTab('list');
|
||||
|
||||
Reference in New Issue
Block a user