add search

This commit is contained in:
Anika Raemer 2025-09-13 14:30:34 +02:00
parent f1a9b6d444
commit df406b636e
3 changed files with 51 additions and 17 deletions

View file

@ -24,10 +24,17 @@ export async function fetchRecipe(id: string): Promise<Recipe> {
/**
* Load list of all recipes
* @param searchString Search string for filtering recipeList
* @returns Array of recipe
*/
export async function fetchRecipeList(): Promise<Recipe[]> {
const res = await fetch(`${RECIPE_URL}/`)
export async function fetchRecipeList(searchString : string): Promise<Recipe[]> {
let url : string = RECIPE_URL;
// if there's a search string add it as query parameter
if(searchString && searchString !== ""){
url +="?search=" + searchString;
}
console.log("calling url", url)
const res = await fetch(url)
if (!res.ok) {
throw new Error(`Failed to fetch recipe list`)
}