refactor: change videoSelected to pass complete video object for better data handling

This commit is contained in:
Chneemann 2025-05-14 19:40:35 +02:00
parent ee95b0d8c5
commit adc3fddd83
4 changed files with 9 additions and 15 deletions

View file

@ -25,7 +25,7 @@ export class CategoriesComponent implements AfterViewInit {
@Input() favoriteVideos: number[] = [];
@Input() watchedVideos: number[] = [];
@Output() currentVideoId = new EventEmitter<number>();
@Output() videoSelected = new EventEmitter<Video>();
environmentBaseUrl: string = environment.baseUrl;
isScrollable: boolean = false;
@ -50,12 +50,9 @@ export class CategoriesComponent implements AfterViewInit {
*
* @param videoId The ID of the video to be opened
*/
openCurrentVideo(videoId: number): void {
const video = this.videos.find((v) => v.id === videoId);
if (video) {
this.currentVideo = video;
this.currentVideoId.emit(videoId);
}
openCurrentVideo(video: Video): void {
this.currentVideo = video;
this.videoSelected.emit(video);
}
/**

View file

@ -15,7 +15,7 @@ export class VideoListComponent {
@Input() currentVideo: Video | null = null;
@Input() watchedVideos: number[] = [];
@Output() videoSelected = new EventEmitter<number>();
@Output() videoSelected = new EventEmitter<Video>();
/**
* Get the URL of the thumbnail image for the given videoId and fileName.
@ -35,7 +35,7 @@ export class VideoListComponent {
const video = this.videos.find((v) => v.id === videoId);
if (video) {
this.currentVideo = video;
this.videoSelected.emit(video.id);
this.videoSelected.emit(video);
}
}

View file

@ -31,7 +31,7 @@
[currentVideo]="currentVideo"
[favoriteVideos]="favoriteVideos"
[watchedVideos]="watchedVideos"
(currentVideoId)="currentVideoId($event)"
(videoSelected)="openCurrentVideo($event)"
></app-categories>
} @else {
<div class="video-overlay">

View file

@ -207,11 +207,8 @@ export class HomeComponent implements OnInit {
/**
* Sets the current video to the given video ID.
*/
currentVideoId(videoId: number): void {
const video = this.videos.find((v) => v.id === videoId);
if (video) {
this.currentVideo = video;
}
openCurrentVideo(video: Video): void {
this.currentVideo = video;
}
/**