fix : race numbers sync with keypad 1 - 30
This commit is contained in:
parent
185d48bc50
commit
dbe0a0497d
@ -3,8 +3,6 @@ import { CommonModule } from '@angular/common';
|
|||||||
import { BtcService } from '../../service/btc.service';
|
import { BtcService } from '../../service/btc.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { catchError, interval, of, Subscription, switchMap } from 'rxjs';
|
import { catchError, interval, of, Subscription, switchMap } from 'rxjs';
|
||||||
// import { HorseService } from '../../service/horseData.service';
|
|
||||||
// import { HorseRaceModel } from '../../model/horseRaceData';
|
|
||||||
import { SharedStateService } from '../../service/shared-state.service';
|
import { SharedStateService } from '../../service/shared-state.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -19,9 +17,6 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
isMenuOpen: boolean = false;
|
isMenuOpen: boolean = false;
|
||||||
screenWidth: number = window.innerWidth;
|
screenWidth: number = window.innerWidth;
|
||||||
private subscription!: Subscription;
|
private subscription!: Subscription;
|
||||||
// public horseDataAndProgramData: HorseRaceModel[] = [];
|
|
||||||
// public raceData: HorseRaceModel[] = [];
|
|
||||||
//private selectedRaceId: number = 0;
|
|
||||||
|
|
||||||
liveStatusOk: boolean = true;
|
liveStatusOk: boolean = true;
|
||||||
|
|
||||||
@ -40,6 +35,7 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
objectKeys = Object.keys;
|
objectKeys = Object.keys;
|
||||||
|
|
||||||
selectedRaceId: number = 0;
|
selectedRaceId: number = 0;
|
||||||
|
enabledHorseNumbers: number[] = [];
|
||||||
|
|
||||||
wallet = {
|
wallet = {
|
||||||
withdraw: 0,
|
withdraw: 0,
|
||||||
@ -93,25 +89,12 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// this.horseService.HorseData.subscribe({
|
|
||||||
// next: (data) => {
|
|
||||||
// if (data === null) return;
|
|
||||||
// console.log('[HORSE DATA] Received:', data);
|
|
||||||
// this.horseDataAndProgramData = data;
|
|
||||||
// },
|
|
||||||
// error: (err) => {
|
|
||||||
// console.error('[HORSE DATA] Error:', err);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
const cachedData = localStorage.getItem('raceCardData');
|
const cachedData = localStorage.getItem('raceCardData');
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
this.raceCardData = JSON.parse(cachedData);
|
this.raceCardData = JSON.parse(cachedData);
|
||||||
console.log('📦 Loaded race card from localStorage:', this.raceCardData);
|
console.log('📦 Loaded race card from localStorage:', this.raceCardData);
|
||||||
|
|
||||||
// ✅ Pre-fill the venue name directly
|
|
||||||
this.selectedVenue = this.raceCardData?.Venue || 'Select Venue';
|
this.selectedVenue = this.raceCardData?.Venue || 'Select Venue';
|
||||||
|
this.updateEnabledHorseNumbers(); // Initialize horse numbers
|
||||||
} else {
|
} else {
|
||||||
this.raceCardData = { raceVenueRaces: { races: [] }, pools: {} };
|
this.raceCardData = { raceVenueRaces: { races: [] }, pools: {} };
|
||||||
console.warn('⚠️ No race card data found in localStorage.');
|
console.warn('⚠️ No race card data found in localStorage.');
|
||||||
@ -140,18 +123,6 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
this.showVenueModal = true;
|
this.showVenueModal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// openRaceModal() {
|
|
||||||
// console.log('[MODAL] Opening race modal');
|
|
||||||
// this.showRaceModal = true;
|
|
||||||
|
|
||||||
// this.horseDataAndProgramData.map((data) => {
|
|
||||||
// if (data.raceId === this.selectedRaceId) {
|
|
||||||
// this.raceData = [data];
|
|
||||||
// }
|
|
||||||
// return data;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
openRaceModal() {
|
openRaceModal() {
|
||||||
console.log('[MODAL] Opening race modal');
|
console.log('[MODAL] Opening race modal');
|
||||||
this.showRaceModal = true;
|
this.showRaceModal = true;
|
||||||
@ -174,20 +145,8 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
this.showLogModal = false;
|
this.showLogModal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectVenue(venue: number) {
|
|
||||||
// console.log('[VENUE] User selected raceId:', venue);
|
|
||||||
// this.selectedRaceId = venue;
|
|
||||||
|
|
||||||
// this.horseDataAndProgramData.map((data) => {
|
|
||||||
// if (data.raceId === venue) {
|
|
||||||
// this.selectedVenue = data.raceVenue?.venue || 'Unknown Venue';
|
|
||||||
// }
|
|
||||||
// return data;
|
|
||||||
// });
|
|
||||||
|
|
||||||
selectVenue(index: number) {
|
selectVenue(index: number) {
|
||||||
const venue = this.raceCardData?.Venue || 'Unknown Venue';
|
const venue = this.raceCardData?.Venue || 'Unknown Venue';
|
||||||
const venueKeys = Object.keys(this.raceCardData?.raceVenueRaces?.races || {});
|
|
||||||
this.selectedVenue = venue;
|
this.selectedVenue = venue;
|
||||||
this.selectedRaceId = index;
|
this.selectedRaceId = index;
|
||||||
|
|
||||||
@ -196,31 +155,12 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
value: this.selectedVenue,
|
value: this.selectedVenue,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log('[VENUE] Venue resolved to:', this.selectedVenue);
|
console.log('[VENUE] Venue resolved to:', this.selectedVenue);
|
||||||
|
|
||||||
this.sharedStateService.updateSharedData({
|
|
||||||
type: 'selectedVenue',
|
|
||||||
value: this.selectedVenue,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('[VENUE] Venue sent to sharedStateService');
|
console.log('[VENUE] Venue sent to sharedStateService');
|
||||||
|
|
||||||
this.closeModals();
|
this.closeModals();
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectRace(race: string) {
|
|
||||||
// this.selectedRace = race;
|
|
||||||
|
|
||||||
// this.sharedStateService.updateSharedData({
|
|
||||||
// type: 'selectedRace',
|
|
||||||
// value: this.selectedRace,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// console.log('[RACE] Race selected:', this.selectedRace);
|
|
||||||
// this.closeModals();
|
|
||||||
// }
|
|
||||||
|
|
||||||
selectRace(race: number) {
|
selectRace(race: number) {
|
||||||
this.selectedRace = race;
|
this.selectedRace = race;
|
||||||
|
|
||||||
@ -229,10 +169,46 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
value: this.selectedRace,
|
value: this.selectedRace,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('[RACE] Race selected:', this.selectedRace);
|
// Push updated runner count from raceCardData
|
||||||
|
const raceCard = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
||||||
|
const raceList = raceCard?.raceVenueRaces?.races || [];
|
||||||
|
const selectedRaceData = raceList[race - 1] || []; // Adjust for 1-based race number
|
||||||
|
const runnerCount = selectedRaceData.length || 12;
|
||||||
|
|
||||||
|
this.sharedStateService.setRunnerCount(runnerCount);
|
||||||
|
this.updateEnabledHorseNumbers(); // Update local horse numbers
|
||||||
|
|
||||||
|
console.log('[RACE] Race selected:', this.selectedRace, '| Runner count:', runnerCount);
|
||||||
this.closeModals();
|
this.closeModals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ✅ Updated method to use exact horseNumbers
|
||||||
|
updateEnabledHorseNumbers() {
|
||||||
|
const raceIndex = this.selectedRace - 1;
|
||||||
|
const race = this.raceCardData?.raceVenueRaces?.races?.[raceIndex];
|
||||||
|
|
||||||
|
if (Array.isArray(race)) {
|
||||||
|
// Assuming each runner has a "horseNumber" property
|
||||||
|
this.enabledHorseNumbers = race
|
||||||
|
.map((runner: any) => runner?.horseNumber)
|
||||||
|
.filter((n: any) => typeof n === 'number' && n >= 1 && n <= 30);
|
||||||
|
} else {
|
||||||
|
this.enabledHorseNumbers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[HORSE NUMBERS] Enabled horse numbers:', this.enabledHorseNumbers);
|
||||||
|
|
||||||
|
this.sharedStateService.updateSharedData({
|
||||||
|
type: 'enabledHorseNumbers',
|
||||||
|
value: this.enabledHorseNumbers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectHorseNumber(number: number) {
|
||||||
|
console.log('[HORSE] Selected horse number:', number);
|
||||||
|
// Add logic to pass the selected number to SelectionService
|
||||||
|
// Example: this.selectionService.updatePartial({ numbers: [...current.numbers, number] });
|
||||||
|
}
|
||||||
|
|
||||||
openWalletModal() {
|
openWalletModal() {
|
||||||
console.log('[MODAL] Opening wallet modal');
|
console.log('[MODAL] Opening wallet modal');
|
||||||
@ -270,19 +246,13 @@ export class NavbarComponent implements OnInit, OnDestroy {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error('Logout print failed');
|
if (!res.ok) throw new Error('Logout print failed');
|
||||||
console.log('[LOGOUT] Print successful');
|
console.log('[LOGOUT] Print successful');
|
||||||
|
|
||||||
// ✅ Close the shared display via Electron
|
|
||||||
(window as any).electronAPI?.closeSecondScreen?.();
|
(window as any).electronAPI?.closeSecondScreen?.();
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
this.router.navigate(['/logout']);
|
this.router.navigate(['/logout']);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('[LOGOUT] Error printing:', err);
|
console.error('[LOGOUT] Error printing:', err);
|
||||||
|
|
||||||
// ✅ Still close the shared display on error
|
|
||||||
(window as any).electronAPI?.closeSecondScreen?.();
|
(window as any).electronAPI?.closeSecondScreen?.();
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
this.router.navigate(['/logout']);
|
this.router.navigate(['/logout']);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -27,8 +27,8 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
isTabletView = false;
|
isTabletView = false;
|
||||||
isTicketingActive = false;
|
isTicketingActive = false;
|
||||||
private resizeObserver!: () => void;
|
private resizeObserver!: () => void;
|
||||||
private currentRaceIdx: number = 0; // Track current race
|
private currentRaceIdx: number = 0;
|
||||||
races: any[] = []; // Store race data
|
races: any[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cdr: ChangeDetectorRef,
|
private cdr: ChangeDetectorRef,
|
||||||
@ -53,7 +53,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
next: (response: HttpResponse<HorseRaceModel[]>) => {
|
next: (response: HttpResponse<HorseRaceModel[]>) => {
|
||||||
const horseRaceData = response.body;
|
const horseRaceData = response.body;
|
||||||
this.horseService.HorseData.next(horseRaceData);
|
this.horseService.HorseData.next(horseRaceData);
|
||||||
this.races = horseRaceData || []; // Populate races for selection
|
this.races = horseRaceData || [];
|
||||||
this.sharedStateService.updateSharedData({
|
this.sharedStateService.updateSharedData({
|
||||||
type: 'horseData',
|
type: 'horseData',
|
||||||
value: horseRaceData,
|
value: horseRaceData,
|
||||||
@ -72,7 +72,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
const raceCardData = res.body;
|
const raceCardData = res.body;
|
||||||
console.log('📦 Race card preloaded:', raceCardData);
|
console.log('📦 Race card preloaded:', raceCardData);
|
||||||
localStorage.setItem('raceCardData', JSON.stringify(raceCardData));
|
localStorage.setItem('raceCardData', JSON.stringify(raceCardData));
|
||||||
this.updateRunnerCount(0); // Initialize with first race
|
this.updateRunnerCount(0);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
console.error('❌ Failed to preload race card:', err);
|
console.error('❌ Failed to preload race card:', err);
|
||||||
@ -80,7 +80,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('📦 Race card already cached');
|
console.log('📦 Race card already cached');
|
||||||
this.updateRunnerCount(0); // Initialize with first race
|
this.updateRunnerCount(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,17 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
|
export interface SharedData {
|
||||||
|
type: string;
|
||||||
|
value: any;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class SharedStateService {
|
export class SharedStateService {
|
||||||
private runnerCountSubject = new BehaviorSubject<number>(12); // Default runner count
|
private runnerCountSubject = new BehaviorSubject<number>(12);
|
||||||
runnerCount$ = this.runnerCountSubject.asObservable();
|
runnerCount$ = this.runnerCountSubject.asObservable();
|
||||||
|
|
||||||
private sharedDataSubject = new BehaviorSubject<any>(null);
|
private sharedDataSubject = new BehaviorSubject<SharedData>({ type: '', value: null });
|
||||||
sharedData$ = this.sharedDataSubject.asObservable();
|
sharedData$ = this.sharedDataSubject.asObservable();
|
||||||
|
|
||||||
private channel = new BroadcastChannel('shared-display-channel');
|
private channel = new BroadcastChannel('shared-display-channel');
|
||||||
@ -16,21 +21,23 @@ export class SharedStateService {
|
|||||||
this.channel.onmessage = (event) => {
|
this.channel.onmessage = (event) => {
|
||||||
console.log('[BroadcastChannel] Received data:', event.data);
|
console.log('[BroadcastChannel] Received data:', event.data);
|
||||||
if (event.data?.runnerCount !== undefined) {
|
if (event.data?.runnerCount !== undefined) {
|
||||||
this.runnerCountSubject.next(event.data.runnerCount); // Sync runner count
|
this.runnerCountSubject.next(event.data.runnerCount);
|
||||||
|
}
|
||||||
|
if (event.data?.type !== undefined && event.data?.value !== undefined) {
|
||||||
|
this.sharedDataSubject.next({ type: event.data.type, value: event.data.value });
|
||||||
}
|
}
|
||||||
this.sharedDataSubject.next(event.data); // Sync other shared data
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setRunnerCount(count: number) {
|
setRunnerCount(count: number) {
|
||||||
console.log('[SharedStateService] Broadcasting runner count:', count);
|
console.log('[SharedStateService] Broadcasting runner count:', count);
|
||||||
this.channel.postMessage({ runnerCount: count }); // Broadcast runner count
|
this.channel.postMessage({ runnerCount: count });
|
||||||
this.runnerCountSubject.next(count); // Update local runner count
|
this.runnerCountSubject.next(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSharedData(data: any) {
|
updateSharedData(data: SharedData) {
|
||||||
console.log('[SharedStateService] Broadcasting data:', data);
|
console.log('[SharedStateService] Broadcasting data:', data);
|
||||||
this.channel.postMessage(data); // Send to other windows
|
this.channel.postMessage(data);
|
||||||
this.sharedDataSubject.next(data); // Update local BehaviorSubject
|
this.sharedDataSubject.next(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user