diff --git a/btc-UI/src/app/components/middle-section/middle-section.component.html b/btc-UI/src/app/components/middle-section/middle-section.component.html index 12c66ee..0ba0dfa 100755 --- a/btc-UI/src/app/components/middle-section/middle-section.component.html +++ b/btc-UI/src/app/components/middle-section/middle-section.component.html @@ -57,10 +57,11 @@ -
+ + diff --git a/btc-UI/src/app/components/middle-section/middle-section.component.ts b/btc-UI/src/app/components/middle-section/middle-section.component.ts index b0c77ce..9f768de 100755 --- a/btc-UI/src/app/components/middle-section/middle-section.component.ts +++ b/btc-UI/src/app/components/middle-section/middle-section.component.ts @@ -16,6 +16,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { filledRows: SelectionData[] = []; currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 }; + grandTotal: number = 0; private selections: SelectionData[] = []; private sub1!: Subscription; @@ -24,13 +25,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { constructor(private selectionService: SelectionService) {} ngOnInit() { - // Subscription for finalized selections this.sub1 = this.selectionService.selections$.subscribe(data => { this.selections = data; this.updateFilledRows(this.selections, this.currentRow); }); - // Subscription for current in-progress row this.sub2 = this.selectionService.currentRow$.subscribe(row => { this.currentRow = row; this.updateFilledRows(this.selections, row); @@ -39,7 +38,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { updateFilledRows(saved: SelectionData[], current: SelectionData) { const rows: SelectionData[] = [...saved]; - if (rows.length < 5) rows.push(current); + if (rows.length < 5 && current.label) rows.push(current); // Include current row if label is selected const emptyCount = Math.max(5 - rows.length, 0); const emptyRows = Array.from({ length: emptyCount }, () => ({ @@ -50,6 +49,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { })); this.filledRows = [...rows, ...emptyRows].slice(0, 5); + this.calculateTotal(); + } + + calculateTotal() { + this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0); } ngOnDestroy() {