refactor: change videoSelected to pass complete video object for better data handling
This commit is contained in:
parent
ee95b0d8c5
commit
adc3fddd83
4 changed files with 9 additions and 15 deletions
|
|
@ -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);
|
|
||||||
if (video) {
|
|
||||||
this.currentVideo = video;
|
this.currentVideo = video;
|
||||||
this.currentVideoId.emit(videoId);
|
this.videoSelected.emit(video);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
|
|
||||||
|
|
@ -207,12 +207,9 @@ 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);
|
|
||||||
if (video) {
|
|
||||||
this.currentVideo = video;
|
this.currentVideo = video;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects a random video from the list as current video.
|
* Selects a random video from the list as current video.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue