small cleanup

This commit is contained in:
fred 2025-07-11 09:41:19 -07:00
parent da0c451141
commit 6f8f03e206

View file

@ -13,24 +13,26 @@ function AddRecipe() {
const [ingredients, setIngredients] = useState<Ingredient[]>([]); const [ingredients, setIngredients] = useState<Ingredient[]>([]);
const [steps, setSteps] = useState<Step[]>([]); const [steps, setSteps] = useState<Step[]>([]);
const [showBulkForm, setShowBulkForm] = useState(true); const [showBulkForm, setShowBulkForm] = useState(true);
const [recipeName, setRecipeName] = useState("");
const [recipeCuisine, setRecipeCuisine] = useState("");
const addRecipeForm = async (event: React.FormEvent) => { const addRecipeForm = async (event: React.FormEvent) => {
event.preventDefault(); event.preventDefault();
const nameElement = document.getElementById('ar-name') as HTMLInputElement | null;
const cuisineElement = document.getElementById('ar-cuisine') as HTMLInputElement | null;
const stepsHash = Object.fromEntries( const stepsHash = Object.fromEntries(
steps.map(step => [step.idx, step.instructions]) steps.map(step => [step.idx, step.instructions])
); );
if (nameElement && cuisineElement) { if (recipeName && recipeCuisine && Object.keys(stepsHash).length > 0 && ingredients.length > 0) {
const recipeData = { const recipeData = {
name: nameElement.value, name: recipeName,
cuisine: cuisineElement.value, cuisine: recipeCuisine,
ingredients: ingredients, ingredients: ingredients,
steps: stepsHash steps: stepsHash
} }
console.log(recipeData) console.log(recipeData)
const data = await addRecipe(recipeData); const data = await addRecipe(recipeData);
setNewRecipeId(data.id); setNewRecipeId(data.id);
} else {
alert('missing required data')
} }
}; };
@ -46,14 +48,16 @@ function AddRecipe() {
<input <input
type="text" type="text"
placeholder="name" placeholder="name"
className="ar-name" className="recipe-name"
id="ar-name" value={recipeName}
onChange={(e) => setRecipeName(e.target.value)}
/> />
<input <input
type="text" type="text"
placeholder="cuisine" placeholder="cuisine"
className="ar-cusine" className="recipe-cusine"
id="ar-cuisine" value={recipeCuisine}
onChange={(e) => setRecipeCuisine(e.target.value)}
/> />
<button type="submit" className="ar-button"> <button type="submit" className="ar-button">
submit submit