From 300cb97b2fe1698c925654220c75a1b7300d6b65 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Mon, 12 May 2025 21:19:52 +0200 Subject: [PATCH] refactor: replace "any" with specific types in several components --- .../home/categories/categories.component.ts | 9 +++++---- .../video-list/video-list.component.html | 4 +++- .../categories/video-list/video-list.component.ts | 12 +++++++++++- .../home/hero-banner/hero-banner.component.ts | 6 +++--- .../home/upload-video/upload-video.component.ts | 14 +++++++++++--- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/components/home/categories/categories.component.ts b/frontend/src/app/components/home/categories/categories.component.ts index 6d599dc..95c04e8 100644 --- a/frontend/src/app/components/home/categories/categories.component.ts +++ b/frontend/src/app/components/home/categories/categories.component.ts @@ -22,8 +22,8 @@ import { GenreService } from '../../../services/genre.service'; export class CategoriesComponent implements AfterViewInit { @Input() videos: Video[] = []; @Input() currentVideo: Video | null = null; - @Input() favoriteVideos: any[] = []; - @Input() watchedVideos: any[] = []; + @Input() favoriteVideos: number[] = []; + @Input() watchedVideos: number[] = []; @Output() currentVideoId = new EventEmitter(); @@ -74,8 +74,9 @@ export class CategoriesComponent implements AfterViewInit { * @returns An array of favorite videos */ getFavoriteVideos(): Video[] { - return this.videos.filter((video) => - this.favoriteVideos.includes(video.id) + return this.videos.filter( + (video) => + video.id !== undefined && this.favoriteVideos.includes(video.id) ); } diff --git a/frontend/src/app/components/home/categories/video-list/video-list.component.html b/frontend/src/app/components/home/categories/video-list/video-list.component.html index 7bfa132..097d793 100644 --- a/frontend/src/app/components/home/categories/video-list/video-list.component.html +++ b/frontend/src/app/components/home/categories/video-list/video-list.component.html @@ -9,9 +9,11 @@ alt="" /> -
+ @if (getWatchedVideos()) { +
+ }
} diff --git a/frontend/src/app/components/home/categories/video-list/video-list.component.ts b/frontend/src/app/components/home/categories/video-list/video-list.component.ts index ec57b47..6917e84 100644 --- a/frontend/src/app/components/home/categories/video-list/video-list.component.ts +++ b/frontend/src/app/components/home/categories/video-list/video-list.component.ts @@ -13,7 +13,7 @@ import { Video } from '../../../../interfaces/video.interface'; export class VideoListComponent { @Input() videos: Video[] = []; @Input() currentVideo: Video | null = null; - @Input() watchedVideos: any[] = []; + @Input() watchedVideos: number[] = []; @Input() videoCategory: string = ''; @Output() currentVideoId = new EventEmitter(); @@ -29,6 +29,16 @@ export class VideoListComponent { return `${environment.baseUrl}/media/thumbnails/${id}/${fileName}_480p.jpg`; } + /** + * Filters and returns all watched videos. + * @returns An array of watched videos. + */ + getWatchedVideos(): Video[] { + return this.videos.filter( + (video) => video.id !== undefined && this.watchedVideos.includes(video.id) + ); + } + /** * Set the current video based on the given videoId and emit the videoId. * @param videoId The id of the video to set as the current video. diff --git a/frontend/src/app/components/home/hero-banner/hero-banner.component.ts b/frontend/src/app/components/home/hero-banner/hero-banner.component.ts index b68ae41..f3b57dc 100644 --- a/frontend/src/app/components/home/hero-banner/hero-banner.component.ts +++ b/frontend/src/app/components/home/hero-banner/hero-banner.component.ts @@ -38,9 +38,9 @@ export class HeroBannerComponent implements OnChanges { [resolution: string]: boolean; }>(); @Output() refreshChange = new EventEmitter(); - @Output() videosChange = new EventEmitter(); - @Output() favoriteVideoChange = new EventEmitter(); - @Output() watchedVideoChange = new EventEmitter(); + @Output() videosChange = new EventEmitter(); + @Output() favoriteVideoChange = new EventEmitter(); + @Output() watchedVideoChange = new EventEmitter(); isVideoLoaded: boolean = false; previewClipUrl: string = ''; diff --git a/frontend/src/app/components/home/upload-video/upload-video.component.ts b/frontend/src/app/components/home/upload-video/upload-video.component.ts index 6e4519b..c400802 100644 --- a/frontend/src/app/components/home/upload-video/upload-video.component.ts +++ b/frontend/src/app/components/home/upload-video/upload-video.component.ts @@ -7,7 +7,11 @@ import { VideoService } from '../../../services/video.service'; import { LoadingDialogComponent } from '../../../shared/components/loading-dialog/loading-dialog.component'; import { Video } from '../../../interfaces/video.interface'; import { GenreService } from '../../../services/genre.service'; -import { HttpEvent, HttpEventType } from '@angular/common/http'; +import { + HttpErrorResponse, + HttpEvent, + HttpEventType, +} from '@angular/common/http'; @Component({ selector: 'app-upload-video', @@ -144,8 +148,12 @@ export class UploadVideoComponent { * Handles upload errors and resets UI state. * @param err - The error from the upload observable */ - private handleUploadError(err: any): void { - this.errorService.handleError(err); + private handleUploadError(err: unknown): void { + if (err instanceof HttpErrorResponse) { + this.errorService.handleError(err); + } else { + console.error('An unknown error occurred during upload:', err); + } this.uploadProgress = null; this.videoData.send = false; }