Skip to content

Commit fd2a6fa

Browse files
committed
Merge pull request 'fix: show toast when user tries to add duplicate ingredient to calculator' (#140) from palette/duplicate-ingredient-toast-feedback-2026-07-25 into main
Reviewed-on: https://git.nice.nz/nice/iscreami/pulls/140
2 parents b70262d + 7a35ea1 commit fd2a6fa

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

.patrol/palette.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Palette — Design / UX Patrol Log
22

3+
## 2026-07-25
4+
- Calculator: ingredient search silently ignored duplicate adds — added toast feedback via rowsRef pattern — opened PR #140
5+
36
## 2026-07-24
47
- RecipesView action buttons grid left empty cell on mobile when Export All was hidden (no recipes) — Import button now spans full width — opened PR #136
58

frontend/src/hooks/useRecipeCalculator.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export function useRecipeCalculator() {
1919
const [isSaving, setIsSaving] = useState(false);
2020
const timerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
2121
const lastErrorAtRef = useRef<number>(0);
22+
const rowsRef = useRef<RecipeRow[]>(rows);
23+
useEffect(() => {
24+
rowsRef.current = rows;
25+
}, [rows]);
2226
const { addToast } = useToast();
2327
const qc = useQueryClient();
2428

@@ -58,8 +62,11 @@ export function useRecipeCalculator() {
5862

5963
const addIngredient = useCallback(
6064
(ingredient: Ingredient, weight_grams = 100) => {
65+
if (rowsRef.current.some((r) => r.ingredient.id === ingredient.id)) {
66+
addToast(`"${ingredient.name}" is already in the recipe`, "info");
67+
return;
68+
}
6169
setRows((prev) => {
62-
if (prev.some((r) => r.ingredient.id === ingredient.id)) return prev;
6370
const next = [
6471
...prev,
6572
{ ingredient, weight_grams, sort_order: prev.length },
@@ -68,7 +75,7 @@ export function useRecipeCalculator() {
6875
return next;
6976
});
7077
},
71-
[profile, triggerCalculate]
78+
[profile, triggerCalculate, addToast]
7279
);
7380

7481
const updateWeight = useCallback(

0 commit comments

Comments
 (0)