-
Notifications
You must be signed in to change notification settings - Fork 60
Handin/recipe libary #57
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
base: main
Are you sure you want to change the base?
Conversation
… shows all recipes after clicking the random button, fixed the CSS styling, added a search function and implemented localStorage
JennieDalgren
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find your netlify link anywhere?
| const sortPopSelect = document.getElementById("sortPop"); | ||
| const searchInput = document.getElementById("search"); | ||
|
|
||
| const renderStars = (num) => "⭐".repeat(num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐
| const CACHE_KEY = "recipesCache"; // localStorage key | ||
| const CACHE_TIME = 6 * 60 * 60 * 1000; // 6 hours in ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
| const query = searchQuery.trim().toLowerCase(); | ||
| if (query) { | ||
| list = list.filter((r) => { | ||
| const inTitle = (r.title || "").toLowerCase().includes(query); | ||
| const inIngredients = (r.ingredients || []).some((i) => | ||
| (i || "").toLowerCase().includes(query) | ||
| ); | ||
| return inTitle || inIngredients; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐
| if (list.length === 0) { | ||
| cardsEl.innerHTML = `<p>No recipes found. Try another filter</p>`; | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great empty state
| // Get the diet type (vegan, vegetarian, etc.) | ||
| const dietText = r.diet; | ||
| // Convert popularity score into stars | ||
| const popularText = renderStars(r.popularity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever
| const ingHtml = r.ingredients.map((i) => `<li>${i}</li>`).join(""); //Här görs igridienslistan om från array till html | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stick to english ;)
| <article class="recipe"> | ||
| <img src="${r.img}" alt="${r.title}" /> | ||
| <h3 class="title">${r.title}</h3> | ||
| <div class="meta"> | ||
| <p><strong>Cuisine:</strong> <span class="cuisine">${cuisineText}</span></p> | ||
| <p><strong>Diet:</strong> <span>${dietText}</span></p> | ||
| <p><strong>Popularity:</strong>${popularText}</p> | ||
| <p><strong>Time:</strong> <span>${timeText}</span></p> | ||
| </div> | ||
| <h4>Ingredients</h4> | ||
| <ul>${ingHtml}</ul> | ||
| </article> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be thorough with indentation of html even inside of js
| cardsEl.innerHTML = renderSingleResult(recipe); | ||
|
|
||
| // Reveal the "Show all" button so the user can restore the list | ||
| showAllButton.style.display = "inline-block"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐ nice ux
| const saved = JSON.parse(cached); | ||
| const tooOld = Date.now() - saved.timestamp > CACHE_TIME; | ||
|
|
||
| // Use cached recipes and render immediately | ||
| if (!tooOld) { | ||
| cardsEl.innerHTML = "<p>Showing recipes from cache</p>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! very good use of a timed cache
| switch (error.message) { | ||
| case "401": | ||
| message = "<p>Invalid or missing API key (401).</p>"; | ||
| break; | ||
| case "402": | ||
| case "429": | ||
| message = ` | ||
| <p>You have reached your daily API quota or are rate-limited (402/429).</p> | ||
| <p>Try again tomorrow, reduce requests, or use cached data.</p> | ||
| `; | ||
| break; | ||
| default: | ||
| message = | ||
| "<p>Could not fetch recipes right now. Please try again later.</p>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice set up of error msgs
|
never mind, I just saw that I reviewed your other PR already! :D |
|
Great! So you find the link?
…________________________________
From: Jennie Dalgren ***@***.***>
Sent: Thursday, October 23, 2025 11:36:07 PM
To: Technigo/js-project-recipe-library ***@***.***>
Cc: AgnesSj01 ***@***.***>; Author ***@***.***>
Subject: Re: [Technigo/js-project-recipe-library] Handin/recipe libary (PR #57)
[https://avatars.githubusercontent.com/u/18549785?s=20&v=4]JennieDalgren left a comment (Technigo/js-project-recipe-library#57)<#57 (comment)>
never mind, I just saw that I reviewed your other PR already! :D
Remember, you don't need to open PR more than once. It will update if you update. And multiple persons can feedback on it.
—
Reply to this email directly, view it on GitHub<#57 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BMAXIAQAHCS2QQNAKRG2HR33ZFC4PAVCNFSM6AAAAACI2I5B7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMZZGMYTMMJZGQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
No description provided.