From 8c24425e03f4e2875e5ce758f37c9335de5e9ffc Mon Sep 17 00:00:00 2001 From: fred Date: Thu, 21 Aug 2025 09:54:27 -0700 Subject: [PATCH] better handling of textbox focus for mobile --- backend/src/models/recipeModel.ts | 7 ++- .../src/components/AddBulkIngredients.tsx | 56 ++++++++++++++++--- frontend/src/components/AddBulkSteps.tsx | 45 +++++++++++---- 3 files changed, 88 insertions(+), 20 deletions(-) diff --git a/backend/src/models/recipeModel.ts b/backend/src/models/recipeModel.ts index dd81ae4..a2f6407 100644 --- a/backend/src/models/recipeModel.ts +++ b/backend/src/models/recipeModel.ts @@ -12,7 +12,7 @@ class RecipeModel { async getAllRecipes(): Promise { try { - logger.info("index page view") + logger.info("index page view"); return await this.prisma.recipes.findMany(); } catch (err) { console.error("Error fetching all recipes:", err); @@ -46,7 +46,10 @@ class RecipeModel { instruction: step.instruction, })), }; - logger.info("recipe page view", { recipe_id: data.details.id, recipe_name: data.details.name }) + logger.info("recipe page view", { + recipe_id: data.details.id, + recipe_name: data.details.name, + }); return data; } catch (err) { console.log("Error finding recipe:", err); diff --git a/frontend/src/components/AddBulkIngredients.tsx b/frontend/src/components/AddBulkIngredients.tsx index 87cb39b..41b2c7b 100644 --- a/frontend/src/components/AddBulkIngredients.tsx +++ b/frontend/src/components/AddBulkIngredients.tsx @@ -1,20 +1,23 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect } from "react"; interface AddBulkIngredientsProps { ingredients: string[]; onChange?: (ingredients: string[]) => void; } -const AddBulkIngredients: React.FC = ({ ingredients, onChange }) => { - const [textValue, setTextValue] = useState(''); +const AddBulkIngredients: React.FC = ({ + ingredients, + onChange, +}) => { + const [textValue, setTextValue] = useState(""); useEffect(() => { - const textRepresentation = ingredients.join('\n'); + const textRepresentation = ingredients.join("\n"); setTextValue(textRepresentation); }, [ingredients]); const parseAndUpdate = (value: string) => { - const lines = value.split('\n').filter(line => line.trim() !== ''); + const lines = value.split("\n").filter((line) => line.trim() !== ""); if (onChange) onChange(lines); }; @@ -24,24 +27,63 @@ const AddBulkIngredients: React.FC = ({ ingredients, on }; const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { + if (e.key === "Enter") { parseAndUpdate(textValue); } }; const handleBlur = () => { parseAndUpdate(textValue); + document.body.style.overflow = ""; + removeTouchListeners(); + }; + + const manageOverflow = () => { + const lineCount = textValue + .split("\n") + .filter((line) => line.trim() !== "").length; + if (lineCount > 8) { + document.body.style.overflow = "hidden"; + addTouchListeners(); + } else { + document.body.style.overflow = ""; + removeTouchListeners(); + } + }; + + const handleFocus = () => { + manageOverflow(); + }; + + const handleTouchEnd = () => { + manageOverflow(); + }; + + const addTouchListeners = () => { + window.addEventListener("touchmove", preventDefault, { passive: false }); + }; + + const removeTouchListeners = () => { + window.removeEventListener("touchmove", preventDefault); + }; + + const preventDefault = (e: TouchEvent) => { + e.preventDefault(); }; return (
-

Ingredients:

+

+ Ingredients: +