diff --git a/README.md b/README.md index 58f1a8a66..e0b5dc706 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # js-project-recipe-library +[https://app.netlify.com/projects/jsprojectrecipelibrary/overview](https://jsprojectrecipelibrary.netlify.app/) +https://github.com/emilfloren96/js-project-recipe-library/commit/3186eec6628fcdd8ef15e5c07345b2b399e00170#r168031360 diff --git a/index.html b/index.html new file mode 100644 index 000000000..a15f9f475 --- /dev/null +++ b/index.html @@ -0,0 +1,39 @@ + + +
+ + +Loading...
"; + + let url = `https://api.spoonacular.com/recipes/complexSearch?number=4&addRecipeInformation=true&apiKey=c4791e847ed74bd093c0b702927d5d37`; + + if (cuisine && cuisine !== "All") { + url += `&cuisine=${cuisine}`; + } + + try { + const res = await fetch(url); + const data = await res.json(); + + currentRecipes = data.results; + renderRecipes(data.results); + } catch (error) { + container.innerHTML = "Failed to fetch recipes.
"; + console.error(error); + } + }; + + + +const renderRecipes = (recipes) => { + container.innerHTML = ""; + +recipes.forEach(recipe => { + container.innerHTML += ` +Searching...
"; + const res = await fetch(url); + const data = await res.json(); + + if (!data.results || data.results.length === 0) { + container.innerHTML = `No API results for "${searchTerm}".
`; + return; + } + + // Filtrera resultaten manuellt på titel och ingredienser + const filtered = data.results.filter(recipe => { + const titleMatch = recipe.title.toLowerCase().includes(searchTerm); + const ingredientMatch = recipe.extendedIngredients?.some(ing => + ing.name.toLowerCase().includes(searchTerm) + ); + return titleMatch || ingredientMatch; + }); + + currentRecipes = filtered; + if (filtered.length > 0) { + renderRecipes(filtered); + } else { + container.innerHTML = `No results found for "${searchTerm}".
`; + } + } catch (error) { + console.error("API Search error:", error); + container.innerHTML = "Failed to fetch from API.
"; + } + } else { + // Lokal sökning + const filtered = localRecipes.filter(recipe => { + const titleMatch = recipe.title.toLowerCase().includes(searchTerm); + const ingredientMatch = recipe.ingredients?.some(ing => + ing.toLowerCase().includes(searchTerm) + ); + return titleMatch || ingredientMatch; + }); + + currentRecipes = filtered; + + if (filtered.length > 0) { + renderRecipes(filtered); + } else { + container.innerHTML = `No local results found for "${searchTerm}".
`; + } + } +}); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 000000000..4212ddce5 --- /dev/null +++ b/style.css @@ -0,0 +1,110 @@ +body { + background-color: #f7f8ff; +} + +h1 { + font-size: 64px; + font-style: bold; + color: #0018A4; +} + +#searchInput { + padding: 12px 20px; + border: 2px solid #ccc; + border-radius: 50px; + font-size: 16px; + transition: all 0.3s ease; + width: 250px; + outline: none; + margin-top: 10px; +} + + +h4 { + display: flex; + align-items: center; +} + +.navBar { + display: flex; +} + +.navBox { + padding: 1%; +} + +.button { +width: fit-content; +Height: 40px; +border-radius: 50px; +Padding: 8px 16px 8px 16px; +Gap: 10px; +} + +.button[data-cuisine="All"] { + background-color: #0018A4; + color: white; +} + +.button[data-cuisine="Italian"] +{ + background-color: #CCFFE2; + color: #0018A4; +} + +.button[data-cuisine="American"] +{ + background-color: #CCFFE2; + color: #0018A4; +} + +.button[data-cuisine="Chinese"] +{ + background-color: #CCFFE2; + color: #0018A4; +} + +.button.descending { + background-color: #FF6589; +} + +.button.ascending, +.button.source { + background-color: #FFECEA; + color: #0018A4; +} + +.button:hover { + text-decoration: underline; +} + +.container { + display: flex; + flex-direction: column; + align-items: center; + margin: 20px; + padding: 20px; +} + +.card { + width: 200px; + height: 100%; + border: 1px solid gray; + border-radius: 10px; + padding: 10px; + margin: 10px; +} + +.card img { + width: 100%; + height: 200px; +} + +@media (min-width: 668px) { + .container{ + display: flex; + flex-direction: row; + justify-content: start; + align-items: self-start; + } +} \ No newline at end of file