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,10 +196,12 @@ 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.watchedVideos = [...this.watchedVideos, videoId];
|
||||||
this.watchedVideoChange.emit(this.watchedVideos);
|
this.watchedVideoChange.emit(this.watchedVideos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles the presence of an item in an array, returning a new array.
|
* Toggles the presence of an item in an array, returning a new array.
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue