fix: prevent toggling watched videos, only add once when not already marked
This commit is contained in:
parent
adc3fddd83
commit
765c3f3000
2 changed files with 23 additions and 21 deletions
|
|
@ -196,8 +196,10 @@ export class HeroBannerComponent implements OnChanges {
|
|||
this.favoriteVideos = this.toggleArrayItem(this.favoriteVideos, videoId);
|
||||
this.favoriteVideoChange.emit(this.favoriteVideos);
|
||||
} else if (statusType === 'watched') {
|
||||
this.watchedVideos = this.toggleArrayItem(this.watchedVideos, videoId);
|
||||
this.watchedVideoChange.emit(this.watchedVideos);
|
||||
if (!this.watchedVideos.includes(videoId)) {
|
||||
this.watchedVideos = [...this.watchedVideos, videoId];
|
||||
this.watchedVideoChange.emit(this.watchedVideos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
@ -145,13 +127,31 @@ export class HomeComponent implements OnInit {
|
|||
}
|
||||
|
||||
/**
|
||||
* Called when favorite videos change.
|
||||
* Called when watched videos change.
|
||||
*/
|
||||
onWatchedVideoChange(watched: number[]): void {
|
||||
this.watchedVideos = watched;
|
||||
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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue