find issue import cards
This commit is contained in:
@@ -9,6 +9,12 @@ interface DeckCardProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function DeckCard({ deck, onEdit }: DeckCardProps) {
|
export default function DeckCard({ deck, onEdit }: DeckCardProps) {
|
||||||
|
|
||||||
|
if(deck.id === "410ed539-a8f4-4bc4-91f1-6c113b9b7e25"){
|
||||||
|
console.log("deck", deck.name);
|
||||||
|
console.log("cardEntities", deck.cards);
|
||||||
|
}
|
||||||
|
|
||||||
const validation = validateDeck(deck);
|
const validation = validateDeck(deck);
|
||||||
const commander = deck.format === 'commander' ? deck.cards.find(card =>
|
const commander = deck.format === 'commander' ? deck.cards.find(card =>
|
||||||
card.is_commander
|
card.is_commander
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ const DeckList = ({ onDeckEdit }: DeckListProps) => {
|
|||||||
.select('*')
|
.select('*')
|
||||||
.eq('deck_id', deck.id);
|
.eq('deck_id', deck.id);
|
||||||
|
|
||||||
if(deck.id === "410ed539-a8f4-4bc4-91f1-6c113b9b7e25"){
|
|
||||||
console.log("deck", deck.name);
|
|
||||||
console.log("cardEntities", cardEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cardsError) {
|
if (cardsError) {
|
||||||
console.error(`Error fetching cards for deck ${deck.id}:`, cardsError);
|
console.error(`Error fetching cards for deck ${deck.id}:`, cardsError);
|
||||||
@@ -40,7 +37,11 @@ const DeckList = ({ onDeckEdit }: DeckListProps) => {
|
|||||||
const cardIds = cardEntities.map((entity) => entity.card_id);
|
const cardIds = cardEntities.map((entity) => entity.card_id);
|
||||||
const uniqueCardIds = [...new Set(cardIds)];
|
const uniqueCardIds = [...new Set(cardIds)];
|
||||||
|
|
||||||
|
if(deck.id === "410ed539-a8f4-4bc4-91f1-6c113b9b7e25"){
|
||||||
console.log("uniqueCardIds", uniqueCardIds);
|
console.log("uniqueCardIds", uniqueCardIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const scryfallCards = await getCardsByIds(uniqueCardIds);
|
const scryfallCards = await getCardsByIds(uniqueCardIds);
|
||||||
|
|||||||
@@ -110,10 +110,11 @@ export default function DeckManager({ initialDeck, onSave }: DeckManagerProps) {
|
|||||||
const [deckName, setDeckName] = useState(initialDeck?.name || '');
|
const [deckName, setDeckName] = useState(initialDeck?.name || '');
|
||||||
const [deckFormat, setDeckFormat] = useState(initialDeck?.format || 'standard');
|
const [deckFormat, setDeckFormat] = useState(initialDeck?.format || 'standard');
|
||||||
const [commander, setCommander] = useState<Card | null>(
|
const [commander, setCommander] = useState<Card | null>(
|
||||||
initialDeck?.cards.find(c =>
|
initialDeck?.cards.find(card =>
|
||||||
c.card.type_line?.toLowerCase().includes('legendary creature')
|
card.is_commander
|
||||||
)?.card || null
|
)?.card || null
|
||||||
);
|
);
|
||||||
|
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const [isImporting, setIsImporting] = useState(false);
|
const [isImporting, setIsImporting] = useState(false);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
@@ -449,7 +450,7 @@ export default function DeckManager({ initialDeck, onSave }: DeckManagerProps) {
|
|||||||
<option value="">Select Commander</option>
|
<option value="">Select Commander</option>
|
||||||
{selectedCards
|
{selectedCards
|
||||||
.filter(c =>
|
.filter(c =>
|
||||||
c.card.type_line?.toLowerCase().includes('legendary creature')
|
c.card.type_line?.toLowerCase().includes('legendary')
|
||||||
)
|
)
|
||||||
.map(({ card }) => (
|
.map(({ card }) => (
|
||||||
<option key={card.id} value={card.id}>
|
<option key={card.id} value={card.id}>
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export const getCardById = async (cardId: string): Promise<Card> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getCardsByIds = async (cardIds: string[]): Promise<Card[]> => {
|
export const getCardsByIds = async (cardIds: string[]): Promise<Card[]> => {
|
||||||
|
|
||||||
|
//75 cards per request max
|
||||||
const response = await fetch(`${SCRYFALL_API}/cards/collection`, {
|
const response = await fetch(`${SCRYFALL_API}/cards/collection`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ const FORMAT_RULES = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function validateDeck(deck: Deck): DeckValidation {
|
export function validateDeck(deck: Deck): DeckValidation {
|
||||||
console.log("deck in validator", deck);
|
|
||||||
const rules = FORMAT_RULES[deck.format as keyof typeof FORMAT_RULES];
|
const rules = FORMAT_RULES[deck.format as keyof typeof FORMAT_RULES];
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
@@ -61,7 +60,7 @@ export function validateDeck(deck: Deck): DeckValidation {
|
|||||||
const cardCounts = new Map<string, number>();
|
const cardCounts = new Map<string, number>();
|
||||||
for (const element of deck.cards) {
|
for (const element of deck.cards) {
|
||||||
const {card, quantity} = element;
|
const {card, quantity} = element;
|
||||||
console.log("card", card);
|
//console.log("card", card);
|
||||||
const currentCount = cardCounts.get(card.id) || 0;
|
const currentCount = cardCounts.get(card.id) || 0;
|
||||||
cardCounts.set(card.id, currentCount + quantity);
|
cardCounts.set(card.id, currentCount + quantity);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user