|
1 | | -import React, { useState, useEffect } from 'react' |
2 | | -import type { generalFormatedItemType } from 'types/displayDataTypes'; |
| 1 | +import { AchievementItem, ItemWithCounter } from '@components/common'; |
| 2 | +import type { fishCaughtType } from 'types/displayDataTypes'; |
3 | 3 |
|
4 | | -interface FishProps { |
5 | | - fishCaught: generalFormatedItemType[]; |
6 | | -} |
7 | | - |
8 | | -const Fish = ({ fishCaught }: FishProps) => { |
9 | | - const [totalFished, setTotalFished] = useState(0); |
10 | | - |
11 | | - const getCraftedItems = (items: generalFormatedItemType[]) => { |
12 | | - return items.map((num) => (num.fished) ? 1 : 0).reduce((n: number, next: number) => next + n, 0); |
13 | | - }; |
14 | | - |
15 | | - useEffect(() => { |
16 | | - setTotalFished(getCraftedItems(fishCaught)); |
17 | | - }, [fishCaught]); |
| 4 | +const Fish = ({ |
| 5 | + fishCaught, |
| 6 | + catchedFish, |
| 7 | + total, |
| 8 | + achievements }: fishCaughtType) => { |
18 | 9 |
|
19 | 10 | return ( |
20 | 11 | <div className="progress-container"> |
21 | | - <span className="a-title"><h1>{ `You've fished ${totalFished} out of ${fishCaught.length}`}</h1></span> |
| 12 | + <span className="a-title"> |
| 13 | + <h2> |
| 14 | + Has fished {fishCaught} out of {total}. |
| 15 | + </h2> |
| 16 | + </span> |
22 | 17 | <br /> |
23 | 18 | <h2>Fishing Achievements</h2> |
24 | | - <ul className="a-List"> |
25 | | - <li>Fisherman: {(totalFished >= 10) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {15 - totalFished} more fish to get this</span> } </li> |
26 | | - <li>Ol' Mariner: {(totalFished >= 24) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {30 - totalFished} more fish to get this </span>}</li> |
27 | | - <li>Master Angler : {(totalFished >= fishCaught.length) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to catch {fishCaught.length - totalFished} more fish to get this </span>}</li> |
28 | | - </ul> |
| 19 | + |
| 20 | + <div className="section-achievements"> |
| 21 | + {achievements && achievements.map((ach, i) => ( |
| 22 | + <AchievementItem |
| 23 | + key={i} |
| 24 | + done={ach.done} |
| 25 | + image={ach.image} |
| 26 | + achievementName={ach.name} |
| 27 | + achievementDesc={ach.description} |
| 28 | + achievementHoverDesc={ach.hoverDesc} |
| 29 | + />))} |
| 30 | + </div> |
29 | 31 | <br /> |
30 | | - {fishCaught.map((fish, i) => <a href={`https://stardewvalleywiki.com/${fish.image}`} target="_blank" rel="noreferrer" key={i}><img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Fishing/${fish.image}.png`} alt={fish.name} className={ (fish.fished) ? "done" : ""} title={(fish.fished) ? `You've caught ${fish.name}` : `You haven't fished ${fish.name}`} ></img></a>)} |
31 | | - |
| 32 | + <div className="item-grid"> |
| 33 | + { catchedFish ? |
| 34 | + catchedFish.map((d, i) => |
| 35 | + <ItemWithCounter |
| 36 | + key={i} |
| 37 | + link={`https://stardewvalleywiki.com/${d.link}`} |
| 38 | + src={`https://stardew-tracker.s3.amazonaws.com/Fishing/${d.image}.png`} |
| 39 | + name={d.name} |
| 40 | + state={ (d.fished) ? "done" : "unknown" } |
| 41 | + hoverDesc={(d.fished) ? `Has caught ${d.name}` |
| 42 | + : `You haven't caught ${d.name}`} |
| 43 | + times={d.fished ? null : undefined} |
| 44 | + />) |
| 45 | + : <div>No fishing data available.</div> |
| 46 | + } |
| 47 | + </div> |
32 | 48 | </div> |
33 | 49 | ); |
34 | 50 | }; |
|
0 commit comments