|
1 | | -import { useState, useEffect } from 'react' |
2 | | -import type { generalFormatedItemType } from 'types/displayDataTypes'; |
3 | | - |
4 | | -interface dishesCookedType { |
5 | | - cookedItems: generalFormatedItemType[]; |
6 | | -} |
7 | | - |
8 | | -const Food = ( {cookedItems} : dishesCookedType) => { |
9 | | - const [dishesCooked, setDishesCooked] = useState(0); |
10 | | - if(!cookedItems) return <div>No cooking data available.</div>; |
11 | | - |
12 | | - const canMap = (cookedItems && cookedItems.length > 0); |
13 | | - console.log("Cooking data:", cookedItems); |
14 | | - useEffect(() => { |
15 | | - const cookedCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0; |
16 | | - setDishesCooked(cookedCount); |
17 | | - }, [cookedItems]); |
18 | | - const cookedCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0; |
19 | | - const knownCount = canMap ? cookedItems.map((num) => (num.times !== undefined && num.times >= 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0; |
| 1 | +import type { cookingDataType } from 'types/displayDataTypes'; |
| 2 | +import { Cook, SousChef, GourmetChef } from '@media/Achievements'; |
| 3 | +import './Cooking.css'; |
20 | 4 |
|
| 5 | +const Food = ( {cookedItems, knownRecipes, alreadyCookedRecipes} : cookingDataType) => { |
21 | 6 | return ( |
22 | 7 | <div className="progress-container"> |
23 | | - <span className="a-title"><h1>You have cooked {cookedCount}, knowing {knownCount} out of {cookedItems.length} recipes</h1></span> |
| 8 | + <span className="a-title"> |
| 9 | + <h2> |
| 10 | + Has cooked {alreadyCookedRecipes}, knowing {knownRecipes} out of 74 recipes |
| 11 | + </h2> |
| 12 | + </span> |
24 | 13 | <br /> |
25 | 14 | <h2>Cooking Achievements</h2> |
26 | | - <ul className="a-List"> |
27 | | - <li>Cook: {(dishesCooked >= 10) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to cook {10 - dishesCooked} more dishes to get this</span> } </li> |
28 | | - <li>Sous Chef: {(dishesCooked >= 25) ? <span className="completed">You have this achievement</span> : <span className="pending"> You need to cook {25 - dishesCooked} more dishes to get this</span> }</li> |
29 | | - <li>Gourmet Chef: {(dishesCooked >= 74) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to cook {74 - dishesCooked} more dishes to get this</span> }</li> |
30 | | - </ul> |
| 15 | + <div className="section-achievements"> |
| 16 | + <div className="achievement-item"> |
| 17 | + <img |
| 18 | + className={`${(alreadyCookedRecipes >= 10) ? |
| 19 | + "achieved" : "pending"}`} |
| 20 | + src={Cook} |
| 21 | + alt="Cook Achievement" |
| 22 | + /> |
| 23 | + <div> |
| 24 | + <h3>Cook:</h3> |
| 25 | + <p>Cook a total of 10 dishes</p> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + <div className="achievement-item"> |
| 29 | + <img |
| 30 | + className={`${(alreadyCookedRecipes >= 25) ? |
| 31 | + "achieved" : "pending"}`} |
| 32 | + src={SousChef} |
| 33 | + alt="Sous Chef Achievement" |
| 34 | + /> |
| 35 | + <div> |
| 36 | + <h3>Sous Chef:</h3> |
| 37 | + <p>Cook a total of 25 dishes</p> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + <div className="achievement-item"> |
| 41 | + <img |
| 42 | + className={`${(alreadyCookedRecipes >= 74) ? |
| 43 | + "achieved" : "pending"}`} |
| 44 | + src={GourmetChef} |
| 45 | + alt="Gourmet Chef Achievement" |
| 46 | + /> |
| 47 | + <div> |
| 48 | + <h3>Gourmet Chef:</h3> |
| 49 | + <p>Cook a total of 74 dishes</p> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
31 | 53 | <br /> |
32 | | - { canMap ? |
33 | | - cookedItems.map((d, i) => <a href={`https://stardewvalleywiki.com/${d.link}`} target="blank" key={i}><img src={`https://stardew-tracker.s3.amazonaws.com/Cooking/${d.image}.png`} alt={d.name} className={ (d.times !== undefined) ? ((d.times > 0) ? "done" : "known" ): "" } title={(d.times !== undefined) ? (d.times > 0) ? `Cooked ${d.name} ${d.times} times` : `You haven't cooked ${d.name}` : `You don't know how to cook ${d.name}`} ></img></a>) |
34 | | - : null |
| 54 | + <div className="dishes-grid"> |
| 55 | + { cookedItems ? |
| 56 | + cookedItems.map((d, i) => |
| 57 | + <a |
| 58 | + href={`https://stardewvalleywiki.com/${d.link}`} |
| 59 | + target="blank" |
| 60 | + key={i} |
| 61 | + className="dish-item"> |
| 62 | + <img |
| 63 | + src={`https://stardew-tracker.s3.amazonaws.com/Cooking/${d.image}.png`} |
| 64 | + alt={d.name} |
| 65 | + className={ (d.times !== undefined) ? ((d.times > 0) ? "done" : "known" ): "" } |
| 66 | + title={(d.times !== undefined) ? |
| 67 | + (d.times > 0) ? `Cooked ${d.name} ${d.times} times` |
| 68 | + : `You haven't cooked ${d.name}` |
| 69 | + : `You don't know how to cook ${d.name}` |
| 70 | + } > |
| 71 | + </img> |
| 72 | + <p className="times-cooked">x{d.times}</p> |
| 73 | + </a>) |
| 74 | + : <div>No cooking data available.</div> |
35 | 75 | } |
| 76 | + </div> |
36 | 77 | </div> |
37 | 78 | ); |
38 | 79 | }; |
|
0 commit comments