add search
This commit is contained in:
parent
f1a9b6d444
commit
df406b636e
3 changed files with 51 additions and 17 deletions
|
|
@ -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`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue