Add functionality to mark video as watched on server when viewed
This commit is contained in:
parent
90dca91f6d
commit
2d3d00c441
4 changed files with 27 additions and 2 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
[screenWidth]="checkScreenWidth()"
|
[screenWidth]="checkScreenWidth()"
|
||||||
[currentMovie]="currentMovie"
|
[currentMovie]="currentMovie"
|
||||||
[favoriteMovies]="favoriteMovies"
|
[favoriteMovies]="favoriteMovies"
|
||||||
|
[watchedMovies]="watchedMovies"
|
||||||
(playMovie)="playVideo($event)"
|
(playMovie)="playVideo($event)"
|
||||||
(movieIsUploadedChange)="onMovieIsUploadedChange($event)"
|
(movieIsUploadedChange)="onMovieIsUploadedChange($event)"
|
||||||
(moviesChange)="onMoviesChange($event)"
|
(moviesChange)="onMoviesChange($event)"
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
[imgPath]="'play'"
|
[imgPath]="'play'"
|
||||||
[imgReverse]="true"
|
[imgReverse]="true"
|
||||||
[disabled]="!isAnyResolutionUploaded()"
|
[disabled]="!isAnyResolutionUploaded()"
|
||||||
(click)="playMovieId(playUrl)"
|
(click)="playMovieId(playUrl, currentMovie[0].id)"
|
||||||
></app-btn-large>
|
></app-btn-large>
|
||||||
<div class="favorite-img" (click)="toggleLikeMovie(currentMovie[0].id)">
|
<div class="favorite-img" (click)="toggleLikeMovie(currentMovie[0].id)">
|
||||||
@if(checkLikeMovies(currentMovie[0].id)) {
|
@if(checkLikeMovies(currentMovie[0].id)) {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ export class HeroBannerComponent implements OnChanges {
|
||||||
@Input() currentMovie: any[] = [];
|
@Input() currentMovie: any[] = [];
|
||||||
@Input() screenWidth: boolean = false;
|
@Input() screenWidth: boolean = false;
|
||||||
@Input() favoriteMovies: any[] = [];
|
@Input() favoriteMovies: any[] = [];
|
||||||
|
@Input() watchedMovies: any[] = [];
|
||||||
@Output() playMovie = new EventEmitter<string>();
|
@Output() playMovie = new EventEmitter<string>();
|
||||||
@Output() movieIsUploadedChange = new EventEmitter<{
|
@Output() movieIsUploadedChange = new EventEmitter<{
|
||||||
[resolution: string]: boolean;
|
[resolution: string]: boolean;
|
||||||
|
|
@ -100,6 +101,22 @@ export class HeroBannerComponent implements OnChanges {
|
||||||
this.favoriteMovieChange.emit(this.favoriteMovies);
|
this.favoriteMovieChange.emit(this.favoriteMovies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleWatchedMovie(movieId: number): void {
|
||||||
|
if (this.watchedMovies.includes(movieId)) {
|
||||||
|
this.watchedMovies = this.watchedMovies.filter((id) => id !== movieId);
|
||||||
|
} else {
|
||||||
|
this.watchedMovies.push(movieId);
|
||||||
|
}
|
||||||
|
this.updateWatchedMovies();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWatchedMovies() {
|
||||||
|
const body = {
|
||||||
|
watched_videos: this.watchedMovies,
|
||||||
|
};
|
||||||
|
this.userService.updateWatchedMovies(body);
|
||||||
|
}
|
||||||
|
|
||||||
checkLikeMovies(videoId: number) {
|
checkLikeMovies(videoId: number) {
|
||||||
return this.favoriteMovies.includes(videoId);
|
return this.favoriteMovies.includes(videoId);
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +137,8 @@ export class HeroBannerComponent implements OnChanges {
|
||||||
this.moviesChange.emit(newMovies);
|
this.moviesChange.emit(newMovies);
|
||||||
}
|
}
|
||||||
|
|
||||||
playMovieId(videoPath: string) {
|
playMovieId(videoPath: string, videoId: number) {
|
||||||
this.playMovie.emit(videoPath);
|
this.playMovie.emit(videoPath);
|
||||||
|
this.toggleWatchedMovie(videoId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,12 @@ export class UserService {
|
||||||
return lastValueFrom(this.http.put(url, likedMovies, { headers }));
|
return lastValueFrom(this.http.put(url, likedMovies, { headers }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateWatchedMovies(watchedMovies: any) {
|
||||||
|
const url = `${environment.baseUrl}/users/watched/${this.currentUserId}/`;
|
||||||
|
const headers = this.getAuthHeaders();
|
||||||
|
return lastValueFrom(this.http.put(url, watchedMovies, { headers }));
|
||||||
|
}
|
||||||
|
|
||||||
private getAuthHeaders(): HttpHeaders {
|
private getAuthHeaders(): HttpHeaders {
|
||||||
let authToken = localStorage.getItem('authToken');
|
let authToken = localStorage.getItem('authToken');
|
||||||
if (!authToken) {
|
if (!authToken) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue