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

View file

@ -15,7 +15,7 @@ export class VideoListComponent {
@Input() currentVideo: Video | null = null; @Input() currentVideo: Video | null = null;
@Input() watchedVideos: number[] = []; @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. * 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); const video = this.videos.find((v) => v.id === videoId);
if (video) { if (video) {
this.currentVideo = video; this.currentVideo = video;
this.videoSelected.emit(video.id); this.videoSelected.emit(video);
} }
} }

View file

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

View file

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