import { ChangeDetectionStrategy, Component } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { DatePipe } from '@angular/common'; import { map, startWith, switchMap } from 'rxjs'; import { ScheduleBlock } from '@/core/models/catalogs.models'; import { UnixTimePipe } from '@/core/pipes/unix-time.pipe'; import { injectCatalogService } from '@/core/services/catalogs.service'; import { injectWebsocketService, WSEvents } from '@/core/services/websocket.service'; @Component({ standalone: true, imports: [UnixTimePipe], providers: [DatePipe], selector: 'app-schedule', templateUrl: './schedule.component.html', styleUrls: ['./schedule.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class ScheduleComponent { private catalogServ = injectCatalogService(); schedule$ = injectWebsocketService() .listen(WSEvents.SCHEDULE, ['schedule_print']) .pipe( startWith(true), switchMap(() => this.catalogServ.getSchedule()), map((schedule) => schedule[0]) ); schedule = toSignal(this.schedule$, { initialValue: [] as ScheduleBlock[] }); }