-
Notifications
You must be signed in to change notification settings - Fork 60
Leon Ekelund - Recipe Project #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeonEkelund
wants to merge
10
commits into
Technigo:main
Choose a base branch
from
LeonEkelund:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4b16cd9
Set up the project
LeonEkelund ba327e0
add JS functionality and some CSS
LeonEkelund 39997db
Fix mediaqueries and other issues
LeonEkelund 68e07cf
Fix some more CSS issues
LeonEkelund 9b4ea3d
fix further CSS styling issues with media queries
LeonEkelund e389226
Add a readme file that is updated
LeonEkelund f17f84f
Clean up the code and add empty-state and API error messages
LeonEkelund ee345ec
Fix the not active all button when loading the page
LeonEkelund 793b29c
Remove the backupdata.js file
LeonEkelund df28926
fix issues with responsiveness and cleanup of some CSS
LeonEkelund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
| # js-project-recipe-library | ||
| Welcome to my Recipe Project — a clean, interactive web app that helps you explore and organize recipes by cuisine and cooking time. | ||
|
|
||
| Features: | ||
| Filter by cuisine: Italian, Mexican, Mediterranean, Asian, Middle Eastern, European | ||
| Sort by time: Quickly find recipes based on how long they take | ||
| Responsive layout and easy to navigate | ||
|
|
||
| Tech Stack: | ||
| Built with modern web tools (HTML, CSS, JavaScript) and deployed via Netlify. | ||
|
|
||
| LINK: https://leonekelund-recipe-project.netlify.app/ | ||
This file contains hidden or 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,61 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Recipe project</title> | ||
| <link rel="stylesheet" href="./style.css"> | ||
|
|
||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
|
|
||
| <h1> Recipe Library </h1> | ||
| <button class="random-recipe-btn" id="randomBtn">🎲</button> | ||
|
|
||
|
|
||
| <div class="filter-sort-container"> | ||
|
|
||
| <section> | ||
| <h2>Filter on kitchen</h2> | ||
|
|
||
| <div class="button-section"> | ||
| <button class="filter-btn active" id="all">All</button> | ||
| <button class="filter-btn" id="Italian">Italian</button> | ||
| <button class="filter-btn" id="Mexican">Mexican</button> | ||
| <button class="filter-btn" id="Mediterranean">Mediterranean</button> | ||
| <button class="filter-btn" id="Asian">Asian</button> | ||
| <button class="filter-btn" id="Middle Eastern">Middle Eastern</button> | ||
| <button class="filter-btn" id="European">European</button> | ||
| </div> | ||
|
|
||
| </section> | ||
|
|
||
|
|
||
|
|
||
| <section> | ||
| <h2>Sort on time</h2> | ||
| <div class="button-section"> | ||
| <button class="sort-btn" id="descending">Descending</button> | ||
| <button class="sort-btn" id="ascending">Ascending</button> | ||
|
|
||
| </section> | ||
| </div> | ||
|
|
||
| </div> | ||
| <br> | ||
| <br> | ||
|
|
||
|
|
||
| <section id="recipesContainer" class="recipes-container"> | ||
|
|
||
|
|
||
|
|
||
| </section> | ||
|
|
||
| <script src="./script.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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,154 @@ | ||
| //API VARIABLES | ||
| const apiKey = "bd0cc269e37b44dc9363d356be6f251a"; | ||
| const url2 = `https://api.spoonacular.com/recipes/complexSearch?number=5&sort=random&addRecipeInformation=true&apiKey=${apiKey}&cuisine=Asian,Italian,Mexican,Mediterranean,Middle Eastern,European`; | ||
|
|
||
|
|
||
|
|
||
| //DOM ELEMENTS | ||
| const recipesContainer = document.getElementById('recipesContainer'); | ||
| const filterBtns = document.querySelectorAll('.filter-btn'); | ||
| const sortBtns = document.querySelectorAll('.sort-btn'); | ||
| const randomBtn = document.getElementById('randomBtn'); | ||
|
|
||
| const showMessage = (message) => { | ||
| recipesContainer.innerHTML = ` | ||
| <div class="message"> | ||
| <p>${message}</p> | ||
| </div> | ||
| `; | ||
| }; | ||
|
|
||
| let recipesData = []; | ||
| let currentRecipes = []; | ||
|
|
||
| // NORMALIZE THE CUISINES | ||
| const normalizeCuisine = (cuisine) => { | ||
| if (!cuisine) return "Unknown"; | ||
|
|
||
| const asianCuisines = ["Chinese", "Japanese", "Thai", "Korean", "Vietnamese", "Indian"]; | ||
LeonEkelund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const middleEasternCuisines = ["Turkish", "Lebanese", "Persian", "Israeli", "Egyptian"]; | ||
| const europeanCuisines = ["French", "Spanish", "German", "Greek", "British"]; | ||
|
|
||
| if (asianCuisines.includes(cuisine)) return "Asian"; | ||
| if (middleEasternCuisines.includes(cuisine)) return "Middle Eastern"; | ||
| if (europeanCuisines.includes(cuisine)) return "European"; | ||
|
|
||
| return cuisine; | ||
| }; | ||
|
|
||
| // FETCHING API | ||
| const fetchData = () => { | ||
| fetch(url2) | ||
| .then(res => res.json()) | ||
| .then(data => { | ||
| if (!data.results) { | ||
| showMessage("Daily API quota reached or an error occurred. Please try again later."); | ||
| return; | ||
| } | ||
|
|
||
| recipesData = data.results.map(recipe => ({ | ||
| id: recipe.id, | ||
| title: recipe.title, | ||
| image: recipe.image, | ||
| readyInMinutes: recipe.readyInMinutes, | ||
| cuisine: normalizeCuisine(recipe.cuisines?.[0]), | ||
| summary: recipe.summary | ||
LeonEkelund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| })); | ||
|
|
||
| currentRecipes = recipesData; | ||
|
|
||
| if (recipesData.length === 0) { | ||
| showMessage("No recipes found."); | ||
LeonEkelund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| showRecipes(recipesData); | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| showMessage("Unable to load recipes. Please check your connection or try again later."); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| fetchData(); | ||
|
|
||
|
|
||
|
|
||
| // FUNCTION TO SHOW RECIPES | ||
| const showRecipes = (recipesToShow = recipesData) => { | ||
|
|
||
| currentRecipes = recipesToShow; | ||
| recipesContainer.innerHTML = ''; | ||
|
|
||
| recipesToShow.forEach(recipe => { | ||
| recipesContainer.innerHTML += ` | ||
| <div class="recipe-card-wrapper"> | ||
| <div class="recipe-card"> | ||
| <p class="recipe-title">${recipe.title}</p> | ||
| <hr class="divider"> | ||
| <p><b>Cuisine:</b> ${recipe.cuisine}</p> | ||
| <hr class="divider"> | ||
| <img src="${recipe.image}" alt="${recipe.title}"> | ||
| <hr class="divider"> | ||
| <p><b>Cooking time:</b> ${recipe.readyInMinutes} minutes!</p> | ||
| <p> ${recipe.summary} </p> | ||
| </div> | ||
| </div> | ||
| `; | ||
| }); | ||
| }; | ||
|
|
||
| // FUNCTION FOR BUTTONS | ||
|
|
||
| //FILTER BUTTONS | ||
| filterBtns.forEach(btn => { | ||
| btn.addEventListener("click", () => { | ||
| const selectedCuisine = btn.id.toLowerCase(); | ||
|
|
||
| const filtered = | ||
| selectedCuisine === "all" | ||
| ? recipesData | ||
| : recipesData.filter(r => r.cuisine.toLowerCase() === selectedCuisine); | ||
|
|
||
| filterBtns.forEach(b => b.classList.remove("active")); | ||
| btn.classList.add("active"); | ||
|
|
||
| if (filtered.length === 0) { | ||
| showMessage(`No ${selectedCuisine} recipes found.`); | ||
| } else { | ||
| showRecipes(filtered); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| // SORT BUTTONS | ||
| sortBtns.forEach(btn => { | ||
| btn.addEventListener("click", () => { | ||
| const order = btn.id; // "ascending" or "descending" | ||
|
|
||
| const sorted = [...currentRecipes].sort((a, b) => | ||
| order === "ascending" | ||
| ? a.readyInMinutes - b.readyInMinutes | ||
| : b.readyInMinutes - a.readyInMinutes | ||
| ); | ||
|
|
||
| sortBtns.forEach(b => b.classList.remove("active")); | ||
| btn.classList.add("active"); | ||
|
|
||
| showRecipes(sorted); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| // RANDOMBUTTON | ||
| randomBtn.addEventListener('click', () => { | ||
| //RANDOMNUMBER | ||
| const randomIndex = Math.floor(Math.random() * recipesData.length); | ||
|
|
||
| const randomRecipe = recipesData[randomIndex]; | ||
|
|
||
| showRecipes([randomRecipe]); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.