import { useNavigate } from "react-router-dom"; import { EngagementViewRecipe } from "../../services/EngagementService"; import { isApiError } from "../../types/api/error"; import type { Recipe } from "../../types/recipe"; import ServingSizeIconSmall from "../icons/ServingSizeIconSmall"; import StarIcon from "../icons/StarIcon"; import TimeIconSmall from "../icons/TimeIconSmall"; import RecipePlaceholder from "../../assets/images/recipe_placeholder.png"; interface RecipeSearchResultProps { recipe: Recipe; }; export default function RecipeSearchResult({ recipe }: RecipeSearchResultProps) { const navigate = useNavigate(); // HANDLERS const clickHandler = async () => { // Navigate first, so it feels faster await navigate(`/v2/web/recipe/${recipe.Id}`); const result = await EngagementViewRecipe(recipe.Id); if (isApiError(result)) { console.error(result.message); } } return (
void clickHandler()} className="w-full p-2 border-b border-gray-200 hover:bg-gray-100 duration-200 flex items-center flex-col md:flex-row even:bg-[#f8f8f8] cursor-pointer"> Recipe placeholder image

{recipe.Title} {recipe.Category}

{recipe.Duration.Total} min {Array.from({ length: recipe.Difficulty }).map((_, i) => ( ))} {Array.from({ length: 5 - (recipe.Difficulty) }).map((_, i) => ( ))} Serves {recipe.Serves}
{recipe.Favorite && ( )}

{recipe.Tags.map(x => x.Name).join(", ")}

{recipe.Description}

); }