diff --git a/frontend/src/pages/AddRecipe.tsx b/frontend/src/pages/AddRecipe.tsx index c496c9d..37bef30 100644 --- a/frontend/src/pages/AddRecipe.tsx +++ b/frontend/src/pages/AddRecipe.tsx @@ -1,11 +1,12 @@ -import React, { useState } from 'react'; +import React, { useState } from "react"; import { addRecipe } from "../services/frontendApi.js"; import { useNavigate } from "react-router-dom"; -import AddBulkIngredients from "../components/AddBulkIngredients.tsx" -import AddBulkSteps from "../components/AddBulkSteps.tsx" -import StarRating from "../components/StarRating.tsx" -import DemoModal from '../components/DemoModal.tsx' -import '../css/colorTheme.css'; +import AddBulkIngredients from "../components/AddBulkIngredients.tsx"; +import AddBulkSteps from "../components/AddBulkSteps.tsx"; +import StarRating from "../components/StarRating.tsx"; +import DemoModal from "../components/DemoModal.tsx"; +import "../css/colorTheme.css"; +import { isProfane } from "../utils/profanityFilter"; interface Step { step_number: number; @@ -28,14 +29,29 @@ function AddRecipe() { const addRecipeForm = async (event: React.FormEvent) => { event.preventDefault(); - if (process.env.NODE_ENV === 'demo') { + if ( + isProfane(recipeName) || + isProfane(recipeCuisine) || + ingredients.some((ingredient) => isProfane(ingredient)) || + steps.some((step) => isProfane(step.instruction)) || + isProfane(author) + ) { + alert("Your submission contains inappropriate language."); + return; + } + if (process.env.NODE_ENV === "demo") { setShowDemoModal(true); return; } const stepsHash = Object.fromEntries( - steps.map(step => [step.step_number, step.instruction]) + steps.map((step) => [step.step_number, step.instruction]), ); - if (recipeName && recipeCuisine && Object.keys(stepsHash).length > 0 && ingredients.length > 0) { + if ( + recipeName && + recipeCuisine && + Object.keys(stepsHash).length > 0 && + ingredients.length > 0 + ) { const recipeData = { name: recipeName, cuisine: recipeCuisine.toLowerCase(), @@ -44,13 +60,13 @@ function AddRecipe() { cook_minutes: cookMinutes, stars: stars, ingredients: ingredients, - steps: stepsHash - } - console.log(recipeData) + steps: stepsHash, + }; + console.log(recipeData); const data = await addRecipe(recipeData); setNewRecipeId(data.id); } else { - alert('missing required data') + alert("missing required data"); } }; @@ -88,7 +104,12 @@ function AddRecipe() { />