33import React , { useCallback , useMemo , useState } from 'react' ;
44import Link from 'next/link' ;
55import { useRouter } from 'next/router' ;
6- import { ChevronDownIcon , ChevronUpIcon } from '@heroicons/react/24/solid' ;
6+ import { CheckCircleIcon , ChevronDownIcon , ChevronUpIcon } from '@heroicons/react/24/solid' ;
77import dynamic from 'next/dynamic' ;
88import Notification from '@/components/Notification.js' ;
99
@@ -38,7 +38,12 @@ const getUnitPrice = ( value ) => {
3838const getTotalPrice = ( item ) =>
3939 getUnitPrice ( item ?. data ?. marketPrice ) * getQuantity ( item ?. card ?. quantity ) ;
4040
41- const YugiohCardDataTable = ( { matchedCardData = [ ] , isAuthenticated = false } ) => {
41+ const YugiohCardDataTable = ( {
42+ matchedCardData = [ ] ,
43+ isAuthenticated = false ,
44+ collectionMap = { } ,
45+ onCollectionUpdated = null ,
46+ } ) => {
4247 const router = useRouter ( ) ;
4348 const itemsPerPage = 15 ;
4449 const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
@@ -60,7 +65,7 @@ const YugiohCardDataTable = ( { matchedCardData = [], isAuthenticated = false }
6065
6166 // Build base key from card properties (without index)
6267 const makeKey = ( { card } ) =>
63- `${ card ?. productName } |${ card ?. setName } |${ card ?. number } |${ card ?. printing } ` ;
68+ `${ card ?. productName } |${ card ?. setName } |${ card ?. number } |${ card ?. printing } | ${ card ?. rarity } ` ;
6469
6570 // Stable unique IDs including duplicate counts
6671 const safeMatchedData = Array . isArray ( matchedCardData ) ? matchedCardData : [ ] ;
@@ -230,10 +235,13 @@ const YugiohCardDataTable = ( { matchedCardData = [], isAuthenticated = false }
230235
231236 if ( ! response . ok ) throw new Error ( ) ;
232237 triggerNotification ( "Card(s) added to the collection!" ) ;
238+ if ( typeof onCollectionUpdated === 'function' ) {
239+ onCollectionUpdated ( ) ;
240+ }
233241 } catch {
234242 triggerNotification ( "Card(s) failed to save!" ) ;
235243 }
236- } , [ isAuthenticated , selectedKeys , safeMatchedData , itemUniqueIds , triggerNotification ] ) ;
244+ } , [ isAuthenticated , selectedKeys , safeMatchedData , itemUniqueIds , triggerNotification , onCollectionUpdated ] ) ;
237245
238246
239247 const downloadCSV = useCallback ( ( ) => {
@@ -404,6 +412,7 @@ const YugiohCardDataTable = ( { matchedCardData = [], isAuthenticated = false }
404412 const uniqueId = itemUniqueIds [ originalIndex ] ;
405413 const isSelected = selectedKeys . has ( uniqueId ) ;
406414 const { card, data } = item ;
415+ const isCollected = isAuthenticated && Boolean ( collectionMap ?. [ item . collectionKey ] ) ;
407416 const quantity = getQuantity ( card ?. quantity ) ;
408417 const totalPrice = getTotalPrice ( item ) ;
409418
@@ -454,7 +463,15 @@ const YugiohCardDataTable = ( { matchedCardData = [], isAuthenticated = false }
454463 } }
455464 className = "block h-full w-full cursor-pointer text-inherit hover:underline"
456465 >
457- { card ?. productName || 'N/A' }
466+ < span className = "inline-flex items-center gap-2" >
467+ { isCollected && (
468+ < CheckCircleIcon
469+ className = "h-4 w-4 shrink-0 text-emerald-300"
470+ aria-label = "In collection"
471+ />
472+ ) }
473+ < span > { card ?. productName || 'N/A' } </ span >
474+ </ span >
458475 </ Link >
459476 ) ;
460477 } ) ( ) }
0 commit comments