Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to display the total volume of a cocktail batch when the batch value is greater than 1. The feature calculates the combined volume of all volume-based ingredients (ml/oz) and displays it as a badge below the ingredients list.
- Adds batch total volume calculation using useMemo for performance optimization
- Displays total volume badge when batch value is not 1
- Minor code style fix (quote consistency)
| ingredient.units, | ||
| user?.preferredUnits, | ||
| ) | ||
| units = volume.units || 'ml' |
There was a problem hiding this comment.
The units variable is being overwritten on each iteration. This means the final units will be determined by the last ingredient processed, which could be inconsistent. Consider determining units based on the user's preferred units or the majority of ingredients instead.
| units = volume.units || 'ml' | |
| if (volume.units) unitsArray.push(volume.units) |
| units = volume.units || 'ml' | ||
| return total + volume.value | ||
| } else { | ||
| // Ignore non-volume ingredients |
There was a problem hiding this comment.
The comment should be more specific about what constitutes 'non-volume ingredients'. Consider listing examples like 'dashes', 'pinches', 'garnishes', etc. for better code documentation.
| // Ignore non-volume ingredients | |
| // Ignore non-volume ingredients (e.g., dashes, pinches, garnishes) |
| const totalValue = data.ingredients.reduce((total, ingredient) => { | ||
| if (ingredient.units === 'oz' || ingredient.units === 'ml') { | ||
| const volume = convertToPreferredUnits( | ||
| ingredient.amount | ||
| ? new Prisma.Decimal(ingredient.amount).toNumber() * batchValue |
There was a problem hiding this comment.
Creating a new Prisma.Decimal instance on each iteration could be inefficient. Consider converting the amount to number once and reusing it, or handle the Decimal multiplication directly without converting to number first.
| const totalValue = data.ingredients.reduce((total, ingredient) => { | |
| if (ingredient.units === 'oz' || ingredient.units === 'ml') { | |
| const volume = convertToPreferredUnits( | |
| ingredient.amount | |
| ? new Prisma.Decimal(ingredient.amount).toNumber() * batchValue | |
| const batchDecimal = new Prisma.Decimal(batchValue); | |
| const totalValue = data.ingredients.reduce((total, ingredient) => { | |
| if (ingredient.units === 'oz' || ingredient.units === 'ml') { | |
| const volume = convertToPreferredUnits( | |
| ingredient.amount | |
| ? new Prisma.Decimal(ingredient.amount).mul(batchDecimal).toNumber() |
No description provided.