1- import React , { useState , useEffect } from 'react'
21import type { museumCollectionType } from 'types/displayDataTypes' ;
32
43interface CollectionProps {
54 museumCollection : museumCollectionType ;
65}
76
8- const Collection = ( { museumCollection } : CollectionProps ) => {
9- const [ totalFound , setTotalFound ] = useState ( 0 ) ;
10- const [ totalDelivered , setTotalDelivered ] = useState ( 0 ) ;
11- const [ total , setTotal ] = useState ( 0 ) ;
12-
13- const getTotalFound = ( ) => {
14- const artifacts = museumCollection . artifacts ;
15- const minerals = museumCollection . minerals ;
16-
17- const totalArtFound = artifacts . reduce ( ( accum , item ) => ( item . found ) ? accum + 1 : accum , 0 ) ;
18- const totalMinFound = minerals . reduce ( ( accum , item ) => ( item . found ) ? accum + 1 : accum , 0 ) ;
19- const totalArtD = artifacts . reduce ( ( accum , item ) => ( item . inMuseum ) ? accum + 1 : accum , 0 ) ;
20- const totalMinD = minerals . reduce ( ( accum , item ) => ( item . inMuseum ) ? accum + 1 : accum , 0 ) ;
21-
22- setTotalFound ( totalArtFound + totalMinFound ) ;
23- setTotalDelivered ( totalArtD + totalMinD ) ;
24- setTotal ( artifacts . length + minerals . length ) ;
25- } ;
26-
7+ const Collection = ( { museumCollection : mc } : CollectionProps ) => {
278 const createCollectionItem = ( item : any , i : number , type : string ) => {
289 return (
2910 < a href = { `https://stardewvalleywiki.com/${ item . image } ` } target = "blank" key = { i } >
@@ -42,30 +23,28 @@ const Collection = ({ museumCollection }: CollectionProps) => {
4223 ) ;
4324 } ;
4425
45- useEffect ( ( ) => {
46- getTotalFound ( ) ;
47- } , [ ] ) ;
48-
4926 return (
5027 < div className = "progress-container" >
5128 < span className = "a-title" >
52- < h1 > { `You've found ${ totalFound } objects and delivered ${ totalDelivered } / ${ total } to the museum` } </ h1 >
29+ < h1 >
30+ { `You've found ${ mc . totalFound || 0 } objects and delivered ${ mc . totalDelivered || 0 } / ${ mc . total || 0 } to the museum` }
31+ </ h1 >
5332 </ span >
5433 < br />
5534 < br />
5635 < h2 > Museum Achievements</ h2 >
5736 < ul className = "a-List" >
58- < li > A Complete Collection: { ( total === totalDelivered ) ?
37+ < li > A Complete Collection: { ( mc . missingItemsText === undefined ) ?
5938 < 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 >
39+ < span className = "pending" > { mc . missingItemsText } </ span >
6140 }
6241 </ li >
6342 </ ul >
6443 < span className = "a-title" > < h1 > Artifacts</ h1 > </ span >
65- { museumCollection . artifacts . map ( ( item , i ) => createCollectionItem ( item , i , "Artifacts" ) ) }
44+ { mc . artifacts . map ( ( item , i ) => createCollectionItem ( item , i , "Artifacts" ) ) }
6645
6746 < span className = "a-title" > < h1 > Minerals</ h1 > </ span >
68- { museumCollection . minerals . map ( ( item , i ) => createCollectionItem ( item , i , "Minerals" ) ) }
47+ { mc . minerals . map ( ( item , i ) => createCollectionItem ( item , i , "Minerals" ) ) }
6948 </ div >
7049 ) ;
7150} ;
0 commit comments