diff --git a/frontend/src/components/RecipesContainer.tsx b/frontend/src/components/RecipesContainer.tsx deleted file mode 100644 index 30b4e20..0000000 --- a/frontend/src/components/RecipesContainer.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import CookbookRecipeTile from "../components/CookbookRecipeTile.tsx" -import { useState, useEffect } from "react"; -import { getRecipes, deleteRecipe } from "../services/frontendApi.js"; -import { type Recipe } from "../types/Recipe" - - - -function RecipesContainer({ recipes }) => { - - return ( -
-

Recipe Index

-
- {recipes.map((recipe) => ( - - ))} -
-
- - ) -} - -return default RecipesContainer diff --git a/frontend/src/pages/Search.tsx b/frontend/src/pages/Search.tsx index fb2bfe0..3512237 100644 --- a/frontend/src/pages/Search.tsx +++ b/frontend/src/pages/Search.tsx @@ -1,7 +1,6 @@ import { useState, useEffect } from "react"; import CookbookRecipeTile from "../components/CookbookRecipeTile.tsx" import { getRecipes, deleteRecipe } from "../services/frontendApi.js"; -import { type Recipe } from "../types/Recipe" @@ -9,15 +8,21 @@ import { type Recipe } from "../types/Recipe" function Search() { const [searchQuery, setSearchQuery] = useState(""); const [recipes, setRecipes] = useState([]); + const [cuisines, setCuisines] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const [shouldFetchRecipes, setShouldFetchRecipes] = useState(true); + const [selectedCuisine, setSelectedCuisine] = useState(""); useEffect(() => { const loadRecipes = async () => { try { const recipes = await getRecipes(); setRecipes(recipes); + console.log(recipes) + const uniqueCuisines: [] = Array.from(new Set(recipes.map(recipe => recipe.cuisine))) + setCuisines(uniqueCuisines) + console.log(cuisines) } catch (error) { console.log(error); setError("Failed to load recipes..."); @@ -38,10 +43,11 @@ function Search() { console.error("Error deleting recipe:", error); } }; + const filteredRecipes = selectedCuisine ? recipes.filter(recipe => recipe.cuisine === selectedCuisine) : recipes; return (
-
{ }} className="add-recipe-form"> +
setSearchQuery(e.target.value)} /> - - - {error &&
{error}
} + {cuisines.map((cuisine) => ( + + ))} +
{error &&
{error}
} {loading ? (
Loading...
) : (
- {recipes.map((recipe) => ( - recipe.name.toLowerCase().startsWith(searchQuery) && + {filteredRecipes.map((recipe) => ( + recipe.name.toLowerCase().startsWith(searchQuery) && + ))}