import { ChangeDetectionStrategy, Component, signal } from '@angular/core'; import { AsyncPipe, DatePipe } from '@angular/common'; import { toObservable } from '@angular/core/rxjs-interop'; import { map, startWith, switchMap } from 'rxjs'; import { EventDatesPipe } from '@/core/pipes/event-dates.pipe'; import { UnixTimePipe } from '@/core/pipes/unix-time.pipe'; import { injectCatalogsService } from '@/core/services/catalogs.service'; import { injectWebsocketService, WSEvents } from '@/core/services/websocket.service'; import { DateTabsComponent } from '@/shared/date-tabs/date-tabs.component'; import { injectEventDates } from './schedule.providers'; @Component({ standalone: true, selector: 'app-schedule', templateUrl: './schedule.component.html', styleUrls: ['./schedule.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, providers: [DatePipe], imports: [AsyncPipe, EventDatesPipe, DateTabsComponent, UnixTimePipe], }) export class ScheduleComponent { private catalogServ = injectCatalogsService(); selectedDate = signal(0); selectedDate$ = toObservable(this.selectedDate); dates$ = injectEventDates(); schedule$ = injectWebsocketService() .listen(WSEvents.SCHEDULE, ['schedule_print']) .pipe( startWith(true), switchMap(() => this.catalogServ.getSchedule()), switchMap((schedule) => this.selectedDate$.pipe(map((block) => schedule[block]))) ); }