import { use, useEffect, useState } from "react"; import SalmonVideo from "../assets/videos/salmon_video.mp4"; import Banner from "../components/Banner"; import ROUTE_CONSTANTS from "../types/routes"; import RecipeLarge from "../components/cards/RecipeCardLarge"; import type { Recipe } from "../types/recipe"; import RecipeCardSmall from "../components/cards/RecipeCardSmall"; import ContentCardSmall from "../components/cards/ContentCardSmall"; import RecipeSearchBar from "../components/inputs/RecipeSearchBar"; import { GetRecipeOfTheWeek } from "../services/RecipeService"; import { isApiError, type ApiError } from "../types/api/error"; import { AuthContext } from "../context/AuthContext"; export default function Home() { // Context const { isLoggedIn } = use(AuthContext); // Page state const [recipeOfTheWeek, setRecipeOfTheWeek] = useState(null); const [madeRecipes, setMadeRecipes] = useState([]); const [viewedRecipes, setViewedRecipes] = useState([]); const [error, setError] = useState(""); // BUG: Remove these useEffect(() => { const recipe: Recipe = { Id: 1, Title: "Classic Pancakes", Description: "Fluffy and delicious pancakes perfect for breakfast.", Instructions: [ "In a bowl, mix all the dry ingredients.", "In another bowl, whisk the wet ingredients.", "Combine both mixes until smooth.", "Heat a non-stick skillet and pour batter.", "Cook until bubbles form, flip and cook the other side.", "Serve warm with syrup." ], Serves: 4, Difficulty: 2, // scale 1-5 (example) Duration: { Total: 20, Prep: 5, Cook: 15 }, Category: "breakfast", Ingredients: [ { Name: "Flour", Quantity: "2 cups" }, { Name: "Milk", Quantity: "1.5 cups" }, { Name: "Egg", Quantity: "1 large" }, { Name: "Baking Powder", Quantity: "2 teaspoons" }, { Name: "Salt", Quantity: "0.5 teaspoon" }, { Name: "Sugar", Quantity: "1 tablespoon" } ], UserId: 101, Modified: new Date("2025-10-30T09:00:00"), Created: new Date("2025-10-01T08:30:00"), Tags: [ { Id: 1, Name: "easy", Created: new Date("2025-01-01T12:00:00") }, { Id: 2, Name: "quick", Created: new Date("2025-01-02T12:00:00") }, { Id: 3, Name: "breakfast", Created: new Date("2025-01-03T12:00:00") } ], Favorite: true }; const recipe2: Recipe = { Id: 2, Title: "Classic Pancakes", Description: "Fluffy and delicious pancakes perfect for breakfast.", Instructions: [ "In a bowl, mix all the dry ingredients.", "In another bowl, whisk the wet ingredients.", "Combine both mixes until smooth.", "Heat a non-stick skillet and pour batter.", "Cook until bubbles form, flip and cook the other side.", "Serve warm with syrup." ], Serves: 4, Difficulty: 2, // scale 1-5 (example) Duration: { Total: 20, Prep: 5, Cook: 15 }, Category: "breakfast", Ingredients: [ { Name: "Flour", Quantity: "2 cups" }, { Name: "Milk", Quantity: "1.5 cups" }, { Name: "Egg", Quantity: "1 large" }, { Name: "Baking Powder", Quantity: "2 teaspoons" }, { Name: "Salt", Quantity: "0.5 teaspoon" }, { Name: "Sugar", Quantity: "1 tablespoon" } ], UserId: 101, Modified: new Date("2025-10-30T09:00:00"), Created: new Date("2025-10-01T08:30:00"), Tags: [ { Id: 1, Name: "easy", Created: new Date("2025-01-01T12:00:00") }, { Id: 2, Name: "quick", Created: new Date("2025-01-02T12:00:00") }, { Id: 3, Name: "breakfast", Created: new Date("2025-01-03T12:00:00") } ], Favorite: true }; setRecipeOfTheWeek(recipe); const recipes: Recipe[] = [recipe, recipe2]; setMadeRecipes(recipes); setViewedRecipes(recipes); }, []); // TODO: Fetch other items when needed // Fetch the recipe of the week useEffect(() => { async function fetch() { const result: Recipe | ApiError = await GetRecipeOfTheWeek(); if (isApiError(result)) { setError(result.message); return; } setRecipeOfTheWeek(result); } void fetch(); }, []); // BUG: Prob remove useEffect(() => { if (error) console.error(error); }, [error]); return ( <> {/* Intro Section */}

Discover Your Next Favorite Meal

Welcome to your ultimate recipe hub! Whether you're a seasoned chef or just starting your culinary adventure, we're here to inspire. Explore thousands of delicious recipes, from quick weeknight dinners to gourmet delights, all at your fingertips. Find exactly what you're craving with our powerful search and intuitive filters, or browse our trending dishes for fresh ideas.

{/* Search Section */}
{/* Highlight Section */}

Our 'Recipe of the Week' is the cream of the crop! We handpick it by looking at what recipes our community loves most. This isn't just about how many people view a recipe; it's also about how many times it's been made, liked, reviewed, and its average rating, all combined to find the true fan favorite of the week. It's our way of highlighting the best recipes that truly resonate with our users!

{/* Lists Section */}

Recently viewed

{isLoggedIn ?
{viewedRecipes && viewedRecipes.length > 0 ? ( <> {viewedRecipes.map((recipe: Recipe) => ( ))} ) : (

No recently viewed recipes

)}
: }

Make again

{isLoggedIn ?
{madeRecipes && madeRecipes.length > 0 ? ( <> {madeRecipes.map((recipe: Recipe) => ( ))} ) : (

No recently made recipes

)}
: }
{/* Call-to-Action Section */} < section className="w-full flex flex-col items-center justify-center mt-16 py-8 md:py-12 bg-gradient-to-br from-blue-100 to-purple-100 text-center" >

Unleash Your Inner Chef!

Have a unique recipe idea? Want to share your culinary masterpiece with the world? It's time to bring your creations to life!

Create Your Recipe! ); }