1.I’ve got a purchase history screen where you can see all the orders. There’s a delete button for each order, but when I tap it… nothing happens. The order just sits there, mocking me.
2.I’ve also got this “Add Drink” screen where you’re supposed to be able to pick a drink and its size. But when I tap on a drink, it’s like the app is ignoring me. No selection, no nothing.
const handleDeleteOrder = useCallback((orderNumber) => {
console.log('Delete button pressed for order:', orderNumber);
Alert.alert(
"Delete Order",
"Are you sure you want to delete this order?",
[
{ text: "Cancel", style: "cancel" },
{
text: "OK",
onPress: () => {
console.log('Deleting order:', orderNumber);
setPurchaseHistory(prevHistory => {
console.log('Previous history:', prevHistory);
const updatedHistory = prevHistory.filter(order => order.orderNumber !== orderNumber);
console.log('Updated history:', updatedHistory);
return updatedHistory;
});
}
}
]
);
}, [setPurchaseHistory]);
const handleAddDrink = useCallback((item, size) => {
if (!prices[item.category] || !prices[item.category][size]) {
console.error(`Price not found for ${item.name} (${size})`);
Alert.alert('Error', `Price not available for ${item.name} (${size})`);
return;
}
setSelectedDrink(item);
setSelectedDrinkSize(size);
}, [prices]);
// In the render function
<TouchableOpacity
style={styles.deleteButton}
onPress={() => handleDeleteOrder(purchase.orderNumber)}
>
<Text style={styles.deleteButtonText}>Delete</Text>
</TouchableOpacity>
<TouchableOpacity
key={size}
style={[
styles.sizeButton,
selectedDrink === item && selectedDrinkSize === size && styles.selectedSizeButton
]}
onPress={() => handleAddDrink(item, size)}
>
<Text style={styles.sizeButtonText}>{size}</Text>
</TouchableOpacity>
I’ve verified that the handleDeleteOrder function in _layout.js is being called using console.log statements, but the state isn’t updating as expected For the Add Drink functionality, I’ve checked that the handleAddDrink function is being called, but it’s not updating the UI or preparing the drink for addition. I’ve made sure that the setPurchaseHistory function is being passed down to the PriceComponent correctly.