👁️
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

go back to merging cards

+30 -4
+30 -4
src/lib/deck-types.ts
··· 161 161 162 162 /** 163 163 * Move a card to a different section 164 - * NOTE: This MOVES the card, it does not merge with existing cards in the target section 164 + * If the card exists in the target section, merge quantities and combine tags 165 165 */ 166 166 export function moveCardToSection( 167 167 deck: Deck, ··· 169 169 fromSection: Section, 170 170 toSection: Section, 171 171 ): Deck { 172 - const card = findCardInSection(deck, scryfallId, fromSection); 173 - if (!card) { 172 + const sourceCard = findCardInSection(deck, scryfallId, fromSection); 173 + if (!sourceCard) { 174 174 return deck; 175 175 } 176 176 177 - // Simply change the section, don't merge with existing cards 177 + const targetCard = findCardInSection(deck, scryfallId, toSection); 178 + 179 + // If card exists in target section, merge quantities and combine tags 180 + if (targetCard) { 181 + const combinedTags = Array.from( 182 + new Set([...(targetCard.tags ?? []), ...(sourceCard.tags ?? [])]), 183 + ); 184 + return { 185 + ...deck, 186 + cards: deck.cards 187 + .filter( 188 + (c) => !(c.scryfallId === scryfallId && c.section === fromSection), 189 + ) 190 + .map((c) => 191 + c.scryfallId === scryfallId && c.section === toSection 192 + ? { 193 + ...c, 194 + quantity: c.quantity + sourceCard.quantity, 195 + tags: combinedTags, 196 + } 197 + : c, 198 + ), 199 + updatedAt: new Date().toISOString(), 200 + }; 201 + } 202 + 203 + // Otherwise just move the card 178 204 return { 179 205 ...deck, 180 206 cards: deck.cards.map((c) =>