import {useEffect, useState} from "react" import RecipeListItem from "./RecipeListItem" import type {RecipeModel} from "../../models/RecipeModel" import {fetchRecipeList} from "../../api/points/CompactRecipePoint" import {useNavigate} from "react-router-dom" import {getRecipeAddUrl, getRecipeDetailUrl, getRecipeListUrl} from "../../routes" import RecipeListToolbar from "./RecipeListToolbar" /** * Displays a list of recipes in a sidebar layout. * Each recipe link fills the available width. */ export default function RecipeListPage() { const navigate = useNavigate() const [recipeList, setRecipeList] = useState(null) const [searchString, setSearchString] = useState("") // load recipes once on render and whenever search string changes // @todo add delay. Only reload list if the search string hasn't changed for ~200 ms useEffect(() => { console.log("loading recipe list with searchString", searchString) const loadRecipeList = async () => { try { // Fetch recipe list const data = await fetchRecipeList(searchString) // @todo add and use compact recipe mapper setRecipeList(data) } catch (err) { console.error(err) } } loadRecipeList() }, [searchString]) const handleAdd = () => { navigate(getRecipeAddUrl()) } if (!recipeList) { return
Loading!
} return ( /*Container spanning entire screen used to center content horizontally */
{/* Container defining the maximum width of the content */}
{/* Header - remains in position when scrolling */}

Recipes

{/*Content - List of recipe cards */}
{recipeList.map((recipe) => ( ))}
) }