Skip to content

Commit

Permalink
Merge pull request #44 from chingu-voyages/ingredients
Browse files Browse the repository at this point in the history
Correct meal name, capitalise nutritions and update API key
  • Loading branch information
Shree-77 authored Oct 31, 2023
2 parents 4f30584 + c1af620 commit 90d2517
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Food-Recipe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function fetchResponses(recipeName) {
if (obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key) && key !== "updated_at") {
result += `${key}: ${obj[key]}, `;
result += `${capitalize_firstLetter(key)}: ${obj[key]}, `;
}
}
result = result.slice(0, -2).split(',').map(item => `<li>${item}</li>`).join("");
Expand All @@ -139,8 +139,9 @@ async function fetchResponses(recipeName) {
const result = filteredDifficultyTags.map((entry) => entry.display_name);
return result;
};
const displayName = data.results[0]?.name;

createRecipe(recipeName, thumbnail, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);
createRecipe(displayName, thumbnail, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);
} else {
console.error("No results found in thumbnail API for:", recipeName);
}
Expand All @@ -151,20 +152,20 @@ async function fetchResponses(recipeName) {

// Function to create a dynamic recipe content box

function createRecipe(recipeName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag) {
function createRecipe(displayName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag) {
const box = document.createElement("div");
box.classList.add("results__result");

const resultIntro = document.createElement("div");
resultIntro.classList.add("results__result--intro");

const recipeDetails = document.createElement("h3");
recipeDetails.textContent = capitalize_firstLetter(recipeName);
recipeDetails.textContent = capitalize_firstLetter(displayName);

const img = document.createElement("img");
img.src = img_url;

const button = createViewRecipeButton(recipeName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);
const button = createViewRecipeButton(displayName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);

resultIntro.appendChild(recipeDetails);
resultIntro.appendChild(button);
Expand All @@ -177,13 +178,13 @@ function createRecipe(recipeName, img_url, video_url, description, countryTag, r

// Function to create a "View Recipe" button and attach a click event

function createViewRecipeButton(recipeName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag) {
function createViewRecipeButton(displayName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag) {
const button = document.createElement("button");
button.classList.add("result__get-recipe");
button.textContent = "View Recipe";

button.addEventListener('click', () => {
addDialog(recipeName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);
addDialog(displayName, img_url, video_url, description, countryTag, rating, cookTime, yields, instructionsTag, nutrition, difficultyTag);
});
return button;
}
Expand Down Expand Up @@ -394,3 +395,7 @@ function clearResults() {
recipeContainer.removeChild(recipeContainer.firstChild);
}
}



//comment on first commit

0 comments on commit 90d2517

Please sign in to comment.