Skip to content

Commit 2049238

Browse files
hh
1 parent 335d38a commit 2049238

5 files changed

Lines changed: 99 additions & 60 deletions

File tree

components/Yugioh/Card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Card = ( { cardData } ) => {
2727
passHref
2828
>
2929
<img
30-
className="lg:object-cover object-scale-down object-top w-full h-72 aspect-video"
30+
className="lg:object-cover object-scale-down object-top w-auto mx-auto h-72 aspect-video"
3131
as="image"
3232
priority="true"
3333
unoptimized="true"

components/Yugioh/GridView.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard } ) => {
154154
{/* FRONT */ }
155155
<div className="flip-card-front rounded-none">
156156
<img
157-
className="aspect-auto object-contain w-fit object-center"
157+
className="aspect-auto object-cover w-full object-center"
158158
as="image"
159159
priority="true"
160160
unoptimized="true"
@@ -201,35 +201,35 @@ const GridView = ( { aggregatedData, onDeleteCard, onUpdateCard } ) => {
201201
</div>
202202
</div>
203203
</div>
204-
<Link
205-
href={ {
206-
pathname: "/yugioh/sets/[letter]/cards/card-details",
207-
query: ( () => {
208-
const fallbackSetName = card.setName || "";
209-
const fallbackCardName = card.productName || "";
210-
const fallbackNumber = card.number || "";
211-
const fallbackRarity = card.rarity || "";
212-
const fallbackEdition = card.printing || "Unknown Edition";
213-
const letterCandidate = ( fallbackSetName || fallbackCardName ).trim();
214-
const computedLetter = letterCandidate ? letterCandidate.charAt( 0 ).toUpperCase() : undefined;
215-
216-
const query = { source: "collection" };
217-
218-
if ( cardInfo?.id ) query.card = cardInfo.id;
219-
if ( computedLetter ) query.letter = computedLetter;
220-
if ( fallbackSetName ) query.set_name = fallbackSetName;
221-
if ( fallbackCardName ) query.card_name = fallbackCardName;
222-
if ( fallbackNumber ) query.set_code = fallbackNumber;
223-
if ( fallbackRarity ) {
224-
query.rarity = fallbackRarity;
225-
query.set_rarity = fallbackRarity;
226-
}
227-
if ( fallbackEdition ) query.edition = fallbackEdition;
228-
229-
return query;
230-
} )()
231-
} }
232-
>
204+
<Link
205+
href={ {
206+
pathname: "/yugioh/sets/[letter]/cards/card-details",
207+
query: ( () => {
208+
const fallbackSetName = card.setName || "";
209+
const fallbackCardName = card.productName || "";
210+
const fallbackNumber = card.number || "";
211+
const fallbackRarity = card.rarity || "";
212+
const fallbackEdition = card.printing || "Unknown Edition";
213+
const letterCandidate = ( fallbackSetName || fallbackCardName ).trim();
214+
const computedLetter = letterCandidate ? letterCandidate.charAt( 0 ).toUpperCase() : undefined;
215+
216+
const query = { source: "collection" };
217+
218+
if ( cardInfo?.id ) query.card = cardInfo.id;
219+
if ( computedLetter ) query.letter = computedLetter;
220+
if ( fallbackSetName ) query.set_name = fallbackSetName;
221+
if ( fallbackCardName ) query.card_name = fallbackCardName;
222+
if ( fallbackNumber ) query.set_code = fallbackNumber;
223+
if ( fallbackRarity ) {
224+
query.rarity = fallbackRarity;
225+
query.set_rarity = fallbackRarity;
226+
}
227+
if ( fallbackEdition ) query.edition = fallbackEdition;
228+
229+
return query;
230+
} )()
231+
} }
232+
>
233233

234234
<p className='hover:cursor-pointer items-end p-2 mx-auto text-shadow text-xl max-w-prose text-center underline hover:no-underline underline-offset-2'>
235235
More Details

components/Yugioh/YugiohCardDataTable.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const YugiohPagination = dynamic(
1212
{ ssr: false }
1313
);
1414

15-
const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
15+
const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData, isAuthenticated = false } ) => {
1616
const router = useRouter();
1717
const itemsPerPage = 15;
1818
const [ currentPage, setCurrentPage ] = useState( 1 );
@@ -146,6 +146,11 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
146146
);
147147

148148
const addToCollection = useCallback( async () => {
149+
if ( !isAuthenticated ) {
150+
triggerNotification( "Log in to add cards to your collection." );
151+
return;
152+
}
153+
149154
if ( selectedKeys.size === 0 ) {
150155
triggerNotification( "No cards were selected to add to the collection!" );
151156
return;
@@ -181,7 +186,7 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
181186
} catch {
182187
triggerNotification( "Card(s) failed to save!" );
183188
}
184-
}, [ selectedKeys, matchedCardData, itemUniqueIds, triggerNotification ] );
189+
}, [ isAuthenticated, selectedKeys, matchedCardData, itemUniqueIds, triggerNotification ] );
185190

186191

187192
const downloadCSV = useCallback( () => {
@@ -215,8 +220,13 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
215220
}, [ selectedKeys, matchedCardData, setMatchedCardData, itemUniqueIds, triggerNotification ] );
216221

217222
const handleGoToCollectionPage = useCallback( () => {
223+
if ( !isAuthenticated ) {
224+
triggerNotification( "Log in to view your collection." );
225+
return;
226+
}
227+
218228
router.push( '/yugioh/my-collection' );
219-
}, [ router ] );
229+
}, [ isAuthenticated, router, triggerNotification ] );
220230

221231
// Format helper for prices
222232
const formatPrice = ( val ) => {
@@ -252,20 +262,24 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
252262
>
253263
Download CSV
254264
</button>
255-
<button
256-
type="button"
257-
className="border border-white rounded-lg px-2 py-2 text-sm text-white font-bold hover:text-black hover:bg-white"
258-
onClick={ addToCollection }
259-
>
260-
Add card(s) to collection
261-
</button>
262-
<button
263-
type="button"
264-
className="border border-white rounded-lg px-2 py-2 text-sm text-white font-bold hover:text-black hover:bg-white"
265-
onClick={ handleGoToCollectionPage }
266-
>
267-
View Collection
268-
</button>
265+
{ isAuthenticated && (
266+
<>
267+
<button
268+
type="button"
269+
className="border border-white rounded-lg px-2 py-2 text-sm text-white font-bold hover:text-black hover:bg-white"
270+
onClick={ addToCollection }
271+
>
272+
Add card(s) to collection
273+
</button>
274+
<button
275+
type="button"
276+
className="border border-white rounded-lg px-2 py-2 text-sm text-white font-bold hover:text-black hover:bg-white"
277+
onClick={ handleGoToCollectionPage }
278+
>
279+
View Collection
280+
</button>
281+
</>
282+
) }
269283
</div>
270284
{/* Table */ }
271285
<div className="w-full mx-auto overflow-x-auto">
@@ -336,7 +350,7 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
336350
onChange={ ( e ) => toggleCheckbox( e, uniqueId ) }
337351
/>
338352
</td>
339-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
353+
<td className="p-2 text-center text-nowrap border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
340354
{ ( () => {
341355
const detailParams = item.detailParams || {};
342356
const rawLetter = router.query?.letter;
@@ -379,22 +393,22 @@ const YugiohCardDataTable = ( { matchedCardData, setMatchedCardData } ) => {
379393
);
380394
} )() }
381395
</td>
382-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
396+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
383397
{ card?.setName || 'N/A' }
384398
</td>
385-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
399+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
386400
{ card?.number || 'N/A' }
387401
</td>
388-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
402+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
389403
{ card?.printing || 'N/A' }
390404
</td>
391-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
405+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
392406
{ card?.rarity || 'N/A' }
393407
</td>
394-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
408+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-left text-white hover:bg-black hover:text-white">
395409
{ card?.condition || card?.condition + " " + card?.printing }
396410
</td>
397-
<td className="p-2 text-center border-t border-gray-100 text-xs lg:text-sm sm:text-left text-white hover:bg-black hover:text-white">
411+
<td className="text-nowrap p-2 text-center border-t border-gray-100 text-xs md:text-sm sm:text-center font-bold text-white hover:bg-black hover:text-white">
398412
{ formatPrice( data?.marketPrice ) }
399413
</td>
400414
</tr>

pages/login.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ const resolveRedirectPath = ( queryParam ) => {
1414
return DEFAULT_REDIRECT_PATH;
1515
}
1616

17-
return queryParam;
17+
const sanitizedPath = queryParam.trim();
18+
19+
if (
20+
sanitizedPath.startsWith( "/api/" ) ||
21+
sanitizedPath === "/api"
22+
) {
23+
return DEFAULT_REDIRECT_PATH;
24+
}
25+
26+
return sanitizedPath;
1827
};
1928

2029
export default function LoginPage() {

pages/yugioh/sets/[letter]/[setName].js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,20 @@ const CardsInSetPage = ( { initialSetName = "", setNameId = null } ) => {
733733
fetchCollectionCards();
734734
}, [ isAuthenticated ] );
735735

736+
useEffect( () => {
737+
if ( isAuthenticated ) {
738+
return;
739+
}
740+
741+
setGridSelectionMode( false );
742+
setSelectedRowIds( ( prev ) => ( Object.keys( prev ).length === 0 ? prev : {} ) );
743+
setBulkSelections( ( prev ) => ( Object.keys( prev ).length === 0 ? prev : {} ) );
744+
setModalVisible( false );
745+
setBulkModalVisible( false );
746+
setSelectedCard( ( prev ) => ( prev === null ? prev : null ) );
747+
setModalVariant( ( prev ) => ( prev === null ? prev : null ) );
748+
}, [ isAuthenticated ] );
749+
736750
useEffect( () => {
737751
if ( viewMode !== "grid" ) {
738752
setGridSelectionMode( false );
@@ -1426,7 +1440,7 @@ const CardsInSetPage = ( { initialSetName = "", setNameId = null } ) => {
14261440
>
14271441
<div className="relative">
14281442
<div className={ cardContainerClasses }>
1429-
{ isCollected && (
1443+
{ isAuthenticated && isCollected && (
14301444
<span className="absolute left-3 top-3 z-20 rounded-full bg-emerald-500/90 px-3 py-1 text-xs font-semibold text-white shadow-sm">
14311445
In Collection
14321446
</span>
@@ -1831,13 +1845,15 @@ const CardsInSetPage = ( { initialSetName = "", setNameId = null } ) => {
18311845
collectionMap={ collectionLookup }
18321846
onRarityChange={ handleRarityOverrideChange }
18331847
autoRarityOptionValue={ AUTO_RARITY_OPTION }
1848+
isAuthenticated={ isAuthenticated }
18341849
/>
18351850
</Suspense>
18361851
</div>
18371852
) }
18381853
</section>
18391854

1840-
{ Object.values( selectedRowIds ).some( Boolean ) &&
1855+
{ isAuthenticated &&
1856+
Object.values( selectedRowIds ).some( Boolean ) &&
18411857
( viewMode === "table" || ( viewMode === "grid" && gridSelectionMode ) ) && (
18421858
<div className="mx-auto mt-8 max-w-7xl px-4 sm:px-6 lg:px-8">
18431859
<div className="rounded-2xl border border-indigo-400/40 bg-indigo-500/10 p-6 text-center shadow-lg">
@@ -1848,7 +1864,7 @@ const CardsInSetPage = ( { initialSetName = "", setNameId = null } ) => {
18481864
</div>
18491865
) }
18501866
</main>
1851-
{ modalVisible && selectedCard && (
1867+
{ isAuthenticated && modalVisible && selectedCard && (
18521868
<div className="sticky inset-0 z-50 flex items-start justify-center bg-black/70 p-4 sm:p-6">
18531869
<div className="glass w-full max-w-lg max-h-[90vh] overflow-y-auto rounded-xl p-6 shadow-xl">
18541870
<h2 className="mb-4 text-xl font-bold">{ selectedCard.productName }</h2>
@@ -1939,7 +1955,7 @@ const CardsInSetPage = ( { initialSetName = "", setNameId = null } ) => {
19391955
</div>
19401956
) }
19411957

1942-
{ bulkModalVisible && (
1958+
{ isAuthenticated && bulkModalVisible && (
19431959
<div className="sticky inset-0 z-50 flex items-start justify-start bg-black/70 p-4 sm:p-6">
19441960
<div className="glass w-full max-w-2xl max-h-[90vh] overflow-y-auto rounded-xl p-6 shadow-xl">
19451961
<h2 className="mb-4 text-xl font-bold">Add Selected Cards</h2>

0 commit comments

Comments
 (0)