From da0c45114162ae321678520b26ec6f5ce013aa79 Mon Sep 17 00:00:00 2001 From: fred <> Date: Thu, 10 Jul 2025 16:34:53 -0700 Subject: [PATCH] add steps --- frontend/src/components/AddBulkSteps.tsx | 60 +++++++++++++++++++ .../src/components/AddIngredientsForm.tsx | 8 +-- frontend/src/components/AddRecipeForm.tsx | 0 frontend/src/components/AddStepsForm.tsx | 51 ++++++++++++++++ frontend/src/pages/AddRecipe.tsx | 25 ++++++-- frontend/src/types/Recipe.ts | 6 +- 6 files changed, 137 insertions(+), 13 deletions(-) delete mode 100644 frontend/src/components/AddRecipeForm.tsx create mode 100644 frontend/src/components/AddStepsForm.tsx diff --git a/frontend/src/components/AddBulkSteps.tsx b/frontend/src/components/AddBulkSteps.tsx index e69de29..8f47101 100644 --- a/frontend/src/components/AddBulkSteps.tsx +++ b/frontend/src/components/AddBulkSteps.tsx @@ -0,0 +1,60 @@ +import React, { useState, useEffect } from 'react'; +import { type Step } from "../types/Recipe"; + +interface AddBulkStepsProps { + steps: Step[]; + onChange?: (steps: Step[]) => void; +} + +const AddBulkSteps: React.FC = ({ steps, onChange }) => { + const [textValue, setTextValue] = useState(''); + + useEffect(() => { + const textRepresentation = steps.map(step => + `${step.instructions}` + ).join('\n'); + setTextValue(textRepresentation); + }, [steps]); + + const handleInputChange = (e: React.ChangeEvent) => { + setTextValue(e.target.value); + }; + + + const parseAndUpdate = (value: string) => { + const lines = value.split('\n').filter(line => line.trim() !== ''); + + const parsedSteps = lines.map((line, idx) => { + return { idx: idx + 1, instructions: line } + }) + + if (onChange) onChange(parsedSteps); + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + parseAndUpdate(textValue); + } + }; + + const handleBlur = () => { + parseAndUpdate(textValue); + }; + + return ( +
+

Please enter each step on a new line

+