web-remote/src/app/components/slides/slide-list/slide-list.component.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-09-06 07:11:19 +00:00
import { Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core';
import { Subscription } from 'rxjs';
import { Slide } from '../../../responses';
import { OpenLPService } from '../../../openlp.service';
@Component({
selector: 'openlp-slide-list',
templateUrl: './slide-list.component.html',
2023-03-01 03:19:16 +00:00
styleUrls: ['./slide-list.component.scss', '../../no-items.scss'],
2021-09-06 07:11:19 +00:00
})
export class SlideListComponent implements OnInit, OnDestroy {
slides: Slide[] = null;
@Output() slideSelected = new EventEmitter<SlideListItem>();
_subscription: Subscription;
2023-03-01 03:19:16 +00:00
loading = false;
2021-09-06 07:11:19 +00:00
constructor(private openlpService: OpenLPService) {
this._subscription = openlpService.stateChanged$.subscribe(item => this.fetchSlides());
}
ngOnInit() {
this.fetchSlides();
}
ngOnDestroy() {
this._subscription.unsubscribe();
}
onSlideSelected(slide: Slide, index: number) {
this.slideSelected.emit({slide, index});
}
fetchSlides() {
2023-03-01 03:19:16 +00:00
this.loading = true;
2021-09-06 07:11:19 +00:00
this.openlpService.getServiceItem().subscribe(serviceItem => {
2023-03-01 03:19:16 +00:00
this.loading = false;
2021-09-06 07:11:19 +00:00
if (serviceItem instanceof Array) {
this.slides = serviceItem;
}
else {
this.slides = serviceItem.slides;
}
});
}
}
export interface SlideListItem {
slide: Slide;
index: number;
}