From 22e2dab830f114039cd43436f7626a7c0b8bc127 Mon Sep 17 00:00:00 2001 From: fred <> Date: Wed, 9 Jul 2025 14:43:45 -0700 Subject: [PATCH] checkpoint --- backend/backendServer.js | 7 +- .../src/components/AddBulkIngredients.tsx | 55 ++++++++++++ frontend/src/components/AddBulkSteps.tsx | 0 .../src/components/AddIngredientsForm.tsx | 87 +++++++++++++++++++ frontend/src/components/AddRecipeForm.tsx | 0 frontend/src/pages/AddRecipe.tsx | 6 ++ frontend/src/pages/Cookbook.tsx | 2 +- 7 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/AddBulkIngredients.tsx create mode 100644 frontend/src/components/AddBulkSteps.tsx create mode 100644 frontend/src/components/AddIngredientsForm.tsx create mode 100644 frontend/src/components/AddRecipeForm.tsx diff --git a/backend/backendServer.js b/backend/backendServer.js index 73af699..ec80b1e 100644 --- a/backend/backendServer.js +++ b/backend/backendServer.js @@ -7,7 +7,9 @@ const app = express(); app.use(cors()); // to remove cors origin error in dev TODO: remove when dockerized app.use(express.json()); -// routes +// ####### ROUTES ####### + +// ### GET ALL RECIPES ### app.get("/recipes", async (req, res) => { try { const recipes = await db('recipes').select('id', 'name'); @@ -18,6 +20,7 @@ app.get("/recipes", async (req, res) => { } }); +// ### GET RECIPE ### app.get("/recipe/:id", async (req, res) => { const id = req.params.id try { @@ -52,6 +55,7 @@ app.get("/recipe/:id", async (req, res) => { } }); +// ### ADD RECIPE ### app.post("/add-recipe", async (req, res) => { const { name, cuisine, ingredients, steps } = req.body; try { @@ -99,6 +103,7 @@ app.post("/add-recipe", async (req, res) => { } }); +// ### DELETE RECIPE ### app.delete("/delete-recipe", async (req, res) => { const { id } = req.body; try { diff --git a/frontend/src/components/AddBulkIngredients.tsx b/frontend/src/components/AddBulkIngredients.tsx new file mode 100644 index 0000000..13c83f0 --- /dev/null +++ b/frontend/src/components/AddBulkIngredients.tsx @@ -0,0 +1,55 @@ +import React, { useState } from 'react'; +import { type Ingredient } from "../types/Recipe" + + +const BulkIngredientsForm: React.FC = () => { + const [ingredients, setIngredients] = useState([]); + + const handleInputChange = (e: React.ChangeEvent) => { + // Split the input by newline to get individual ingredients + const lines = e.target.value.split('\n').filter(line => line.trim() !== ''); + const pattern = /^([0-9/.]+)?\s*(\S+)\s*((\w+\s*)*)$/; + const parsedIngredients: Ingredient[] = lines.map(line => { + const parts = line.match(pattern); // Updated regex pattern for fractions + let quantity; + if (parts?.[1]) { + // Try to parse the quantity as a fraction first + const [num, denom] = parts[1].split('/'); + if (denom) { + quantity = parseFloat(num) / parseFloat(denom); + } else { + quantity = parseFloat(parts[1]); + } + } else { + quantity = 0; // Default to zero if no quantity is found + } + return { + quantity: +quantity.toFixed(2), + name: parts?.[3]?.trim() || '', + unit: parts?.[2]?.trim() || '' + }; + }); + setIngredients(parsedIngredients); + }; + + return ( +
+

Please enter ingredients in the following order: Quantity, Unit, Name

{/* Prompt for correct input format */} +