fix: prevent toggling watched videos, only add once when not already marked

This commit is contained in:
Chneemann 2025-05-14 20:01:39 +02:00
parent adc3fddd83
commit 765c3f3000
2 changed files with 23 additions and 21 deletions

View file

@ -196,8 +196,10 @@ export class HeroBannerComponent implements OnChanges {
this.favoriteVideos = this.toggleArrayItem(this.favoriteVideos, videoId); this.favoriteVideos = this.toggleArrayItem(this.favoriteVideos, videoId);
this.favoriteVideoChange.emit(this.favoriteVideos); this.favoriteVideoChange.emit(this.favoriteVideos);
} else if (statusType === 'watched') { } else if (statusType === 'watched') {
this.watchedVideos = this.toggleArrayItem(this.watchedVideos, videoId); if (!this.watchedVideos.includes(videoId)) {
this.watchedVideoChange.emit(this.watchedVideos); this.watchedVideos = [...this.watchedVideos, videoId];
this.watchedVideoChange.emit(this.watchedVideos);
}
} }
} }

View file

@ -118,24 +118,6 @@ export class HomeComponent implements OnInit {
} }
} }
/**
* Updates user's liked videos in the backend.
*/
private updateLikedVideos(): void {
const body = {
liked_videos: this.favoriteVideos,
};
this.userService.updateLikedVideos(body);
}
/**
* Updates user's liked videos in the backend.
*/
private updateWatchedVideos(): void {
const body = { watched_videos: this.watchedVideos };
this.userService.updateWatchedVideos(body);
}
/** /**
* Called when favorite videos change. * Called when favorite videos change.
*/ */
@ -145,13 +127,31 @@ export class HomeComponent implements OnInit {
} }
/** /**
* Called when favorite videos change. * Called when watched videos change.
*/ */
onWatchedVideoChange(watched: number[]): void { onWatchedVideoChange(watched: number[]): void {
this.watchedVideos = watched; this.watchedVideos = watched;
this.updateWatchedVideos(); this.updateWatchedVideos();
} }
/**
* Updates user's watched videos in the backend.
*/
private updateWatchedVideos(): void {
const body = { watched_videos: this.watchedVideos };
this.userService.updateWatchedVideos(body);
}
/**
* Updates user's liked videos in the backend.
*/
private updateLikedVideos(): void {
const body = {
liked_videos: this.favoriteVideos,
};
this.userService.updateLikedVideos(body);
}
/** /**
* Updates current video after refresh. * Updates current video after refresh.
*/ */