Skip to content

Commit bde4a75

Browse files
committed
Refactor AchieveTabs types and props usage
Updated Collection and Fish components to use imported types from 'types/displayDataTypes' instead of inline interfaces. Simplified Cooking component logic to expect recipesCooked as an array directly, removing nested property access. These changes improve type consistency and simplify prop handling across AchieveTabs components.
1 parent af8625a commit bde4a75

3 files changed

Lines changed: 12 additions & 29 deletions

File tree

src/Components/AchieveTabs/Collection.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
import React, { useState, useEffect } from 'react'
2+
import type { museumCollectionType } from 'types/displayDataTypes';
23

34
interface CollectionProps {
4-
museumCollection: {
5-
artifacts: Array<{
6-
found: boolean;
7-
inMuseum: boolean;
8-
image: string;
9-
name: string;
10-
}>;
11-
minerals: Array<{
12-
found: boolean;
13-
inMuseum: boolean;
14-
image: string;
15-
name: string;
16-
}>;
17-
};
5+
museumCollection: museumCollectionType;
186
}
197

20-
const Collection: React.FC<CollectionProps> = ({ museumCollection }) => {
8+
const Collection = ({ museumCollection }: CollectionProps) => {
219
const [totalFound, setTotalFound] = useState(0);
2210
const [totalDelivered, setTotalDelivered] = useState(0);
2311
const [total, setTotal] = useState(0);

src/Components/AchieveTabs/Cooking.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const Food = ( recipesCooked : dishesCookedType) => {
99
const [dishesCooked, setDishesCooked] = useState(0);
1010
if(!recipesCooked) return <div>No cooking data available.</div>;
1111

12-
const canMap = (recipesCooked.recipesCooked && recipesCooked.recipesCooked.length > 0);
12+
const canMap = (recipesCooked && recipesCooked.length > 0);
1313
useEffect(() => {
14-
const cookedCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
14+
const cookedCount = canMap ? recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
1515
setDishesCooked(cookedCount);
1616
}, [recipesCooked]);
17-
const cookedCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
18-
const knownCount = canMap ? recipesCooked.recipesCooked.map((num) => (num.times !== undefined && num.times >= 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
17+
const cookedCount = canMap ? recipesCooked.map((num) => (num.times !== undefined && num.times > 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
18+
const knownCount = canMap ? recipesCooked.map((num) => (num.times !== undefined && num.times >= 0) ? 1 : 0).reduce((n: number, next: number) => n + next, 0) : 0;
1919

2020
return (
2121
<div className="progress-container">
22-
<span className="a-title"><h1>You have cooked {cookedCount}, knowing {knownCount} out of {recipesCooked.recipesCooked.length} recipes</h1></span>
22+
<span className="a-title"><h1>You have cooked {cookedCount}, knowing {knownCount} out of {recipesCooked.length} recipes</h1></span>
2323
<br />
2424
<h2>Cooking Achievements</h2>
2525
<ul className="a-List">

src/Components/AchieveTabs/Fish.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import React, { useState, useEffect } from 'react'
2-
3-
interface FishItem {
4-
fished: boolean;
5-
image: string;
6-
name: string;
7-
}
2+
import type { generalFormatedItemType } from 'types/displayDataTypes';
83

94
interface FishProps {
10-
fishCaught: FishItem[];
5+
fishCaught: generalFormatedItemType[];
116
}
127

13-
const Fish: React.FC<FishProps> = ({ fishCaught }) => {
8+
const Fish = ({ fishCaught }: FishProps) => {
149
const [totalFished, setTotalFished] = useState(0);
1510

16-
const getCraftedItems = (items: FishItem[]) => {
11+
const getCraftedItems = (items: generalFormatedItemType[]) => {
1712
return items.map((num) => (num.fished) ? 1 : 0).reduce((n: number, next: number) => next + n, 0);
1813
};
1914

0 commit comments

Comments
 (0)