Skip to content

Commit 9ef0da8

Browse files
hh
1 parent 026b4b5 commit 9ef0da8

62 files changed

Lines changed: 188 additions & 9035 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/Yugioh/GridView.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ const formatCurrency = ( value ) => {
1313
return `$${ numeric.toFixed( 2 ) }`;
1414
};
1515

16+
const normalizeOptionalString = ( value ) => {
17+
if ( value === null || value === undefined ) {
18+
return null;
19+
}
20+
21+
const normalized = String( value ).trim();
22+
return normalized || null;
23+
};
24+
25+
const getPrimaryCardImage = ( card ) => (
26+
Array.isArray( card?.card_images )
27+
? card.card_images.find( ( image ) => image?.id || image?.image_url || image?.image_url_cropped || image?.image_url_small )
28+
: null
29+
);
30+
1631
const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard, sortConfig, handleSortChange, selectedCardIds, onSelectedCardIdsChange, folderNameMap = {} } ) => {
1732
const [ edit, setEdit ] = useState( {} );
1833
const [ editValues, setEditValues ] = useState( {} );
@@ -116,10 +131,20 @@ const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard, sortConfig, han
116131

117132
const getCardImageSources = useCallback(
118133
( card ) => {
119-
const localImageSrc = card?.cardId ? getFullImagePath( card.cardId ) : null;
120-
const remoteImageSrc = typeof card?.remoteImageUrl === "string" && card.remoteImageUrl.trim()
121-
? card.remoteImageUrl.trim()
122-
: null;
134+
const primaryCardImage = getPrimaryCardImage( card );
135+
const imageId =
136+
normalizeOptionalString( primaryCardImage?.id ) ||
137+
normalizeOptionalString( card?.cardImageId ) ||
138+
normalizeOptionalString( card?.cardId ) ||
139+
normalizeOptionalString( card?.cardDetailId ) ||
140+
normalizeOptionalString( card?.id );
141+
const localImageSrc = imageId ? getFullImagePath( imageId ) : null;
142+
const remoteImageSrc =
143+
normalizeOptionalString( card?.remoteImageUrl ) ||
144+
normalizeOptionalString( card?.image_url ) ||
145+
normalizeOptionalString( primaryCardImage?.image_url ) ||
146+
normalizeOptionalString( primaryCardImage?.image_url_cropped ) ||
147+
normalizeOptionalString( primaryCardImage?.image_url_small );
123148
const primaryImageSrc = remoteImageSrc || localImageSrc || FALLBACK_IMAGE;
124149
const secondaryImageSrc = primaryImageSrc === remoteImageSrc ? localImageSrc : remoteImageSrc;
125150

@@ -252,6 +277,13 @@ const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard, sortConfig, han
252277
if ( !card ) return null;
253278

254279
const { primaryImageSrc, secondaryImageSrc } = getCardImageSources( card );
280+
const primaryCardImage = getPrimaryCardImage( card );
281+
const detailCardId =
282+
normalizeOptionalString( primaryCardImage?.id ) ||
283+
normalizeOptionalString( card?.cardImageId ) ||
284+
normalizeOptionalString( card?.cardId ) ||
285+
normalizeOptionalString( card?.cardDetailId ) ||
286+
normalizeOptionalString( card?.id );
255287
const cardId = String( card._id ?? "" );
256288
const isSelected = isSelectionEnabled && selectedCardIds.has( cardId );
257289
const isFlipped = Boolean( flippedCards[ card._id ] );
@@ -278,7 +310,7 @@ const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard, sortConfig, han
278310
const cardDetailsQuery = ( () => {
279311
const query = { source: "collection" };
280312

281-
if ( card.cardId ) query.card = card.cardId;
313+
if ( detailCardId ) query.card = detailCardId;
282314
if ( computedLetter ) query.letter = computedLetter;
283315
if ( card.setName ) query.set_name = card.setName;
284316
if ( card.productName ) query.card_name = card.productName;

components/Yugioh/YugiohCardDataTable.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ const getUnitPrice = ( value ) => {
3838
const getTotalPrice = ( item ) =>
3939
getUnitPrice( item?.data?.marketPrice ) * getQuantity( item?.card?.quantity );
4040

41+
const getOptionalString = ( value ) => {
42+
if ( value === null || value === undefined ) {
43+
return null;
44+
}
45+
46+
const normalized = String( value ).trim();
47+
return normalized || null;
48+
};
49+
50+
const getCollectionCardId = ( item ) =>
51+
getOptionalString( item?.cardImageId ) ||
52+
getOptionalString( item?.cardDetailId ) ||
53+
getOptionalString( item?.detailParams?.cardId ) ||
54+
getOptionalString( item?.card?.cardId ) ||
55+
getOptionalString( item?.card?.cardDetailId ) ||
56+
getOptionalString( item?.variant?.productID ) ||
57+
getOptionalString( item?.resolvedVariant?.productID );
58+
59+
const getCollectionRemoteImageUrl = ( item ) =>
60+
getOptionalString( item?.remoteImageUrl ) ||
61+
getOptionalString( item?.card?.remoteImageUrl );
62+
4163
const YugiohCardDataTable = ( {
4264
matchedCardData = [],
4365
isAuthenticated = false,
@@ -212,16 +234,23 @@ const YugiohCardDataTable = ( {
212234
selectedKeys.has( itemUniqueIds[ index ] )
213235
);
214236

215-
const collectionArray = selectedData.map( ( { card, data } ) => ( {
216-
productName: card?.productName,
217-
setName: card?.setName,
218-
number: card?.number,
219-
printing: card?.printing,
220-
rarity: card?.rarity,
221-
condition: card?.condition,
222-
marketPrice: data?.marketPrice,
223-
quantity: getQuantity( card?.quantity ),
224-
} ) );
237+
const collectionArray = selectedData.map( ( item ) => {
238+
const { card, data } = item;
239+
240+
return {
241+
cardId: getCollectionCardId( item ),
242+
productName: card?.productName,
243+
setName: card?.setName,
244+
number: card?.number,
245+
printing: card?.printing,
246+
rarity: card?.rarity,
247+
condition: card?.condition,
248+
marketPrice: data?.marketPrice,
249+
lowPrice: data?.lowPrice,
250+
remoteImageUrl: getCollectionRemoteImageUrl( item ),
251+
quantity: getQuantity( card?.quantity ),
252+
};
253+
} );
225254

226255
try {
227256
const response = await fetch( `/api/Yugioh/cards`, {

components/ui/accordion.tsx

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)