Display dynamic seat count and total price per category

Updated seat-selection component to show the actual number of selected seats and calculate the total price per seat category. Integrated SelectedSeatsService and replaced hardcoded values with computed properties for better accuracy and maintainability.
This commit is contained in:
2025-11-13 02:14:40 +01:00
parent 9c9e9becfb
commit 31108859da
3 changed files with 15 additions and 8 deletions

View File

@@ -25,9 +25,7 @@
@for (seatCategory of seatCategories(); track $index) { @for (seatCategory of seatCategories(); track $index) {
<div class="h-2"></div> <div class="h-2"></div>
<app-seat-selection <app-seat-selection [seatCategory]="seatCategory"></app-seat-selection>
[seatCategory]="seatCategory"
></app-seat-selection>
} }
@empty { @empty {
<app-no-seats-in-hall></app-no-seats-in-hall> <app-no-seats-in-hall></app-no-seats-in-hall>

View File

@@ -6,6 +6,6 @@
</mat-icon> </mat-icon>
<p>{{ getPriceDisplay(seatCategory().price) }}</p> <p>{{ getPriceDisplay(seatCategory().price) }}</p>
</div> </div>
<p>×&thinsp;2</p> <p>×&thinsp;{{selectedSeatsByCategory()}}</p>
<p class="w-2/7 text-right">25.00 €</p> <p class="w-2/7 text-right">{{ getPriceDisplay(totalPrice())}}</p>
</div> </div>

View File

@@ -1,4 +1,5 @@
import { Component, input } from '@angular/core'; import { SelectedSeatsService } from './../selected-seats.service';
import { Component, computed, inject, input } from '@angular/core';
import { Sitzkategorie } from '@infinimotion/model-frontend'; import { Sitzkategorie } from '@infinimotion/model-frontend';
@Component({ @Component({
@@ -9,10 +10,18 @@ import { Sitzkategorie } from '@infinimotion/model-frontend';
}) })
export class SeatSelectionComponent { export class SeatSelectionComponent {
seatCategory = input.required<Sitzkategorie>(); seatCategory = input.required<Sitzkategorie>();
amount: number = 1;
SelectedSeatsService = inject(SelectedSeatsService);
selectedSeatsByCategory = computed(() =>
this.SelectedSeatsService.getSelectedSeatsByCategory(this.seatCategory().id).length
);
totalPrice = computed(() =>
this.selectedSeatsByCategory() * this.seatCategory().price
);
getPriceDisplay(price: number): string { getPriceDisplay(price: number): string {
return `${(price / 100).toFixed(2)}`; return `${(price / 100).toFixed(2)}`;
} }
} }