-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CORE_Built first version of recipe factory
- Loading branch information
Showing
19 changed files
with
4,712 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"indent":["error", 4] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function displayRecipes(recipes) { | ||
const recipesArr = recipes; | ||
// recipesArr.forEach(recipe => console.log('recipe id: ', recipe.id, ', recipe name', recipe.name, ', number of ingredients : ', recipe.ingredients.length)) | ||
} | ||
function displayRecipe(recipe) { | ||
const recipe1 = recipe; | ||
} | ||
export { displayRecipes }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"use strict"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
"use strict"; | ||
function recipeFactory(recipeContent) { | ||
const { id, name, servings, ingredients, time, description, appliance, ustensils } = recipeContent; | ||
const resultSection = document.getElementById('result-section'); | ||
const template = document.getElementById('template_recipe').content; | ||
const templateClone = document.importNode(template, true); | ||
const recipe = templateClone.querySelector('.recipe'); | ||
const recipeTitle = templateClone.querySelector('.recipe-title'); | ||
const recipeTime = templateClone.querySelector('.recipe-time'); | ||
const recipeIngredients = templateClone.querySelector('.recipe-ingredients'); | ||
const recipeDescription = templateClone.querySelector('.recipe-description'); | ||
recipe.setAttribute('id', `${id}`); | ||
recipe.setAttribute('data-appliance', `${appliance}`); | ||
recipe.setAttribute('data-ustensils', `${ustensils}`); | ||
recipe.setAttribute('data-servings', `${servings}`); | ||
recipeTime.textContent = `${time} min`; | ||
recipeTitle.textContent = name; | ||
ingredients.forEach(ingredient => { | ||
const li = document.createElement('li'); | ||
const b = document.createElement('b'); | ||
b.textContent = `${ingredient.ingredient}`; | ||
li.appendChild(b); | ||
if (ingredient.quantity !== null && ingredient.quantity !== undefined) { | ||
const span = document.createElement('span'); | ||
span.textContent = `: ${ingredient.quantity}`; | ||
if (ingredient.unit !== null && ingredient.unit !== undefined) { | ||
span.textContent = `: ${ingredient.quantity} ${ingredient.unit}`; | ||
} | ||
li.appendChild(span); | ||
} | ||
recipeIngredients.appendChild(li); | ||
}); | ||
recipeDescription.textContent = `${description}`; | ||
resultSection.appendChild(templateClone); | ||
} | ||
export { recipeFactory }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
export {}; | ||
import { recipes } from './data/recipes.js'; | ||
import { recipeFactory } from './factory/recipeFactory.js'; | ||
function init() { | ||
recipes.forEach(recipe => recipeFactory(recipe)); | ||
} | ||
const searchbar = document.getElementById('searchbar'); | ||
searchbar.addEventListener('keyup', handleKeyUp); | ||
function handleKeyUp() { | ||
// Note : prevent other keys than [AZ-az, space] to trigger search | ||
if (searchbar.value.length >= 3) { | ||
console.log('3 or more characters in searchbar:', searchbar.value); | ||
} | ||
} | ||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.