-
-
Notifications
You must be signed in to change notification settings - Fork 0
add batch total volume to cocktail sheet #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,9 @@ import { | |||||
| Plus, | ||||||
| Settings2, | ||||||
| Share, | ||||||
| X | ||||||
| X, | ||||||
| } from 'lucide-react' | ||||||
| import { Fragment, useState } from 'react' | ||||||
| import { Fragment, useMemo, useState } from 'react' | ||||||
| import { | ||||||
| convertToPreferredUnits, | ||||||
| simplifyValue, | ||||||
|
|
@@ -79,6 +79,34 @@ export function CocktailSheet({ | |||||
| const { data } = cocktailQuery | ||||||
| const { data: userCocktailData } = userCocktailQuery | ||||||
|
|
||||||
| const batchTotalVolume = useMemo(() => { | ||||||
| if (!data) return { value: 0, units: 'ml' } | ||||||
|
|
||||||
| let units = 'ml' | ||||||
|
|
||||||
| 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 | ||||||
| : 0, | ||||||
| ingredient.units, | ||||||
| user?.preferredUnits, | ||||||
| ) | ||||||
| units = volume.units || 'ml' | ||||||
|
||||||
| units = volume.units || 'ml' | |
| if (volume.units) unitsArray.push(volume.units) |
Copilot
AI
Jul 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.