@if (cards.length > 0) {
- @for (card of cards; track card) {
+ @for (card of cardsWithState; track card.id) {
}
} @else {
@@ -31,6 +32,33 @@ import { Card } from '../../models/blackjack.model';
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class DealerHandComponent {
+export class DealerHandComponent implements OnChanges {
@Input() cards: Card[] = [];
+ cardsWithState: (Card & { isNew: boolean; id: string })[] = [];
+
+ private lastCardCount = 0;
+
+ ngOnChanges(changes: SimpleChanges): void {
+ if (changes['cards']) {
+ this.updateCardsWithState();
+ }
+ }
+
+ private updateCardsWithState(): void {
+ const newCards = this.cards.length > this.lastCardCount;
+
+ this.cardsWithState = this.cards.map((card, index) => {
+ // Consider a card new if it's added after the initial state and is the latest card
+ const isNew = newCards && index >= this.lastCardCount;
+
+ return {
+ ...card,
+ isNew,
+ // Generate a unique ID to help Angular track the cards
+ id: `${card.suit}-${card.rank}-${index}`
+ };
+ });
+
+ this.lastCardCount = this.cards.length;
+ }
}
diff --git a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
index 3e75315..899417f 100644
--- a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts
@@ -19,28 +19,48 @@ import { Card } from '../../models/blackjack.model';
@@ -52,6 +72,7 @@ import { Card } from '../../models/blackjack.model';
export class GameControlsComponent {
@Input() playerCards: Card[] = [];
@Input() gameState: string = 'IN_PROGRESS';
+ @Input() isActionInProgress: boolean = false;
@Output() hit = new EventEmitter
();
@Output() stand = new EventEmitter();
diff --git a/frontend/src/app/feature/game/blackjack/components/game-info/game-info.component.ts b/frontend/src/app/feature/game/blackjack/components/game-info/game-info.component.ts
index e35bf73..f6b6091 100644
--- a/frontend/src/app/feature/game/blackjack/components/game-info/game-info.component.ts
+++ b/frontend/src/app/feature/game/blackjack/components/game-info/game-info.component.ts
@@ -86,10 +86,15 @@ import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angula
@@ -101,6 +106,7 @@ export class GameInfoComponent implements OnChanges {
@Input() balance = 0;
@Input() currentBet = 0;
@Input() gameInProgress = false;
+ @Input() isActionInProgress = false;
@Output() newGame = new EventEmitter