Skip to content

Commit fabc908

Browse files
committed
Refactor collection item rendering in Collection tab
Extracted repeated artifact and mineral rendering logic into a reusable createCollectionItem function for improved readability and maintainability. Also updated useEffect dependency to run only once on mount.
1 parent d92412a commit fabc908

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

  • src/Components/AchieveTabs/Collection

src/Components/AchieveTabs/Collection/index.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,48 @@ const Collection = ({ museumCollection }: CollectionProps) => {
2424
setTotal(artifacts.length + minerals.length);
2525
};
2626

27+
const createCollectionItem = (item: any, i: number, type: string) => {
28+
return (
29+
<a href={`https://stardewvalleywiki.com/${item.image}`} target="blank" key={i}>
30+
<img
31+
key={i}
32+
src={`https://stardew-tracker.s3.amazonaws.com/${type}/${item.image}.png`}
33+
alt={item.name}
34+
className={ (item.found) ? item.inMuseum ? "done" : "known": "" }
35+
title={(item.found) ? (item.inMuseum) ?
36+
`You have delivered ${item.name} to the museum` :
37+
`You haven't delivered ${item.name} to the museum` :
38+
`You haven't found ${item.name} yet`
39+
}
40+
/>
41+
</a>
42+
);
43+
};
44+
2745
useEffect(() => {
2846
getTotalFound();
29-
}, [museumCollection]);
47+
}, []);
3048

3149
return (
3250
<div className="progress-container">
33-
<span className="a-title"><h1>{`You've found ${totalFound} objects and delivered ${totalDelivered} / ${total} to the museum`}</h1></span>
51+
<span className="a-title">
52+
<h1>{`You've found ${totalFound} objects and delivered ${totalDelivered} / ${total} to the museum`}</h1>
53+
</span>
3454
<br />
3555
<br />
3656
<h2>Museum Achievements</h2>
3757
<ul className="a-List">
38-
<li>A Complete Collection: {(total === totalDelivered) ? <span className="completed">You have this achievement</span> : <span className="pending">You need to deliver {total - totalDelivered} more items to get this achievement.</span> } </li>
58+
<li>A Complete Collection: {(total === totalDelivered) ?
59+
<span className="completed">You have this achievement</span> :
60+
<span className="pending">You need to deliver {total - totalDelivered} more items to get this achievement.</span>
61+
}
62+
</li>
3963
</ul>
4064
<span className="a-title"><h1>Artifacts</h1></span>
41-
{museumCollection.artifacts.map((item, i) => <a href={`https://stardewvalleywiki.com/${item.image}`} target="blank" key={i}><img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Artifacts/${item.image}.png`} alt={item.name} className={ (item.found) ? item.inMuseum ? "done" : "known": "" } title={(item.found) ? (item.inMuseum) ? `You have delivered ${item.name} to the museum` : `You haven't delivered ${item.name} to the museum` : `You haven't found ${item.name} yet`} ></img></a>)}
65+
{museumCollection.artifacts.map((item, i) => createCollectionItem(item, i, "Artifacts"))}
4266

4367
<span className="a-title"><h1>Minerals</h1></span>
44-
{museumCollection.minerals.map((item, i) => <a href={`https://stardewvalleywiki.com/${item.image}`} target="blank" key={i}><img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Minerals/${item.image}.png`} alt={item.name} className={ (item.found) ? item.inMuseum ? "done" : "known" : "" } title={(item.found) ? (item.inMuseum) ? `You have delivered ${item.name} to the museum` : `You haven't delivered ${item.name} to the museum` : `You haven't found ${item.name} yet`} ></img></a>)}
68+
{museumCollection.minerals.map((item, i) => createCollectionItem(item, i, "Minerals"))}
4569
</div>
4670
);
4771
};

0 commit comments

Comments
 (0)