display & save favorite movies
This commit is contained in:
parent
142bed640e
commit
5fc3e5b062
5 changed files with 74 additions and 49 deletions
|
|
@ -14,9 +14,11 @@
|
||||||
"
|
"
|
||||||
[screenWidth]="checkScreenWidth()"
|
[screenWidth]="checkScreenWidth()"
|
||||||
[currentMovie]="currentMovie"
|
[currentMovie]="currentMovie"
|
||||||
|
[favoriteMovies]="favoriteMovies"
|
||||||
(playMovie)="playVideo($event)"
|
(playMovie)="playVideo($event)"
|
||||||
(movieIsUploadedChange)="onMovieIsUploadedChange($event)"
|
(movieIsUploadedChange)="onMovieIsUploadedChange($event)"
|
||||||
(moviesChange)="onMoviesChange($event)"
|
(moviesChange)="onMoviesChange($event)"
|
||||||
|
(favoriteMovieChange)="onFavoriteMovieChange($event)"
|
||||||
></app-hero-banner>
|
></app-hero-banner>
|
||||||
<!-- Spacer -->
|
<!-- Spacer -->
|
||||||
<div *ngIf="!this.checkScreenWidth()" class="spacer"></div>
|
<div *ngIf="!this.checkScreenWidth()" class="spacer"></div>
|
||||||
|
|
@ -28,6 +30,7 @@
|
||||||
"
|
"
|
||||||
[movies]="movies"
|
[movies]="movies"
|
||||||
[currentMovie]="currentMovie[0]?.id"
|
[currentMovie]="currentMovie[0]?.id"
|
||||||
|
[favoriteMovies]="favoriteMovies"
|
||||||
(currentMovieId)="currentMovieId($event)"
|
(currentMovieId)="currentMovieId($event)"
|
||||||
></app-categories>
|
></app-categories>
|
||||||
} @else {
|
} @else {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { CommonModule } from '@angular/common';
|
||||||
import { VideoPlayerComponent } from './video-player/video-player.component';
|
import { VideoPlayerComponent } from './video-player/video-player.component';
|
||||||
import { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component';
|
import { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component';
|
||||||
import { UploadMovieComponent } from './upload-movie/upload-movie.component';
|
import { UploadMovieComponent } from './upload-movie/upload-movie.component';
|
||||||
|
import { UserService } from '../../../services/user.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-browse',
|
selector: 'app-browse',
|
||||||
|
|
@ -27,6 +28,7 @@ import { UploadMovieComponent } from './upload-movie/upload-movie.component';
|
||||||
export class BrowseComponent implements OnInit {
|
export class BrowseComponent implements OnInit {
|
||||||
@ViewChild(VideoPlayerComponent) videoPlayer!: VideoPlayerComponent;
|
@ViewChild(VideoPlayerComponent) videoPlayer!: VideoPlayerComponent;
|
||||||
movies: any[] = [];
|
movies: any[] = [];
|
||||||
|
favoriteMovies: number[] = [];
|
||||||
currentMovie: any[] = [];
|
currentMovie: any[] = [];
|
||||||
playMovie: string = '';
|
playMovie: string = '';
|
||||||
isWideScreen: boolean = false;
|
isWideScreen: boolean = false;
|
||||||
|
|
@ -40,16 +42,34 @@ export class BrowseComponent implements OnInit {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private movieService: MovieService
|
private movieService: MovieService,
|
||||||
|
public userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
|
this.loadLikedMovies();
|
||||||
await this.loadAllMovies();
|
await this.loadAllMovies();
|
||||||
if (this.checkScreenWidth()) {
|
if (this.checkScreenWidth()) {
|
||||||
this.currentMovie.length === 0 ? this.loadRandomMovie() : null;
|
this.currentMovie.length === 0 ? this.loadRandomMovie() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async loadLikedMovies() {
|
||||||
|
try {
|
||||||
|
const likedMovies = await this.userService.getLikedMovies();
|
||||||
|
this.favoriteMovies = likedMovies.liked_videos;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLikeMovies() {
|
||||||
|
const body = {
|
||||||
|
liked_videos: this.favoriteMovies,
|
||||||
|
};
|
||||||
|
this.userService.updateLikedMovies(body);
|
||||||
|
}
|
||||||
|
|
||||||
onMoviesChange(updatedMovies: any[]) {
|
onMoviesChange(updatedMovies: any[]) {
|
||||||
if (this.checkScreenWidth()) {
|
if (this.checkScreenWidth()) {
|
||||||
this.loadRandomMovie();
|
this.loadRandomMovie();
|
||||||
|
|
@ -66,6 +86,11 @@ export class BrowseComponent implements OnInit {
|
||||||
this.movieIsUploaded = newStatus;
|
this.movieIsUploaded = newStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFavoriteMovieChange(favoriteMovies: any) {
|
||||||
|
this.favoriteMovies = favoriteMovies;
|
||||||
|
this.updateLikeMovies();
|
||||||
|
}
|
||||||
|
|
||||||
changeResolution(resolution: '480p' | '720p' | '1080p') {
|
changeResolution(resolution: '480p' | '720p' | '1080p') {
|
||||||
if (this.videoPlayer && this.movieIsUploaded[resolution.replace('p', '')]) {
|
if (this.videoPlayer && this.movieIsUploaded[resolution.replace('p', '')]) {
|
||||||
this.videoPlayer.switchResolution(resolution);
|
this.videoPlayer.switchResolution(resolution);
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,12 @@
|
||||||
<div *ngIf="recentMovies().length > 0" class="category">
|
<div *ngIf="recentMovies().length > 0" class="category">
|
||||||
<p>Added in the last 7 days</p>
|
<p>Added in the last 7 days</p>
|
||||||
<div class="movies">
|
<div class="movies">
|
||||||
<!-- Filme hier einfügen -->
|
<!-- Load movies -->
|
||||||
@for (movie of recentMovies(); track movie) {
|
@for (movie of recentMovies(); track movie) {
|
||||||
<div class="movie" (click)="openCurrentMovie(movie.id)">
|
<div class="movie" (click)="openCurrentMovie(movie.id)">
|
||||||
<img
|
<img
|
||||||
[ngClass]="{ selected: movie.id === currentMovie }"
|
[ngClass]="{ selected: movie.id === currentMovie }"
|
||||||
src="{{
|
[src]="getThumbnailUrl(movie.id, movie.file_name)"
|
||||||
environmentBaseUrl +
|
|
||||||
'/media/thumbnails/' +
|
|
||||||
movie.id +
|
|
||||||
'/' +
|
|
||||||
movie.file_name +
|
|
||||||
'_480p.jpg'
|
|
||||||
}}"
|
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -28,6 +21,32 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Column for favorites -->
|
||||||
|
<div *ngIf="favoriteMovies.length > 0" class="category">
|
||||||
|
<p>Favorites</p>
|
||||||
|
<div class="movies">
|
||||||
|
<!-- Load movies -->
|
||||||
|
@for (favorite of favoriteMovies; track favorite) {
|
||||||
|
<!-- Filter movies -->
|
||||||
|
@for (movie of movies; track movie) {
|
||||||
|
<!-- If movie favorite -->
|
||||||
|
@if (movie.id === favorite) {
|
||||||
|
<div class="movie" (click)="openCurrentMovie(movie.id)">
|
||||||
|
<img
|
||||||
|
[ngClass]="{ selected: movie.id === currentMovie }"
|
||||||
|
[src]="getThumbnailUrl(movie.id, movie.file_name)"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
} } }
|
||||||
|
<!-- Buttons for scrolling -->
|
||||||
|
<div class="scroll-buttons">
|
||||||
|
<button class="scroll-left" (click)="scrollLeft($event)"></button>
|
||||||
|
<button class="scroll-right" (click)="scrollRight($event)"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Genre columns -->
|
<!-- Genre columns -->
|
||||||
@for (filmGenre of filmGenres; track filmGenre) {
|
@for (filmGenre of filmGenres; track filmGenre) {
|
||||||
<!-- Movie available in genre -->
|
<!-- Movie available in genre -->
|
||||||
|
|
@ -35,18 +54,12 @@
|
||||||
<div class="category">
|
<div class="category">
|
||||||
<p>{{ filmGenre.name }}</p>
|
<p>{{ filmGenre.name }}</p>
|
||||||
<div class="movies">
|
<div class="movies">
|
||||||
|
<!-- Load movies -->
|
||||||
@for (movie of allMovies(filmGenre.code); track movie) {
|
@for (movie of allMovies(filmGenre.code); track movie) {
|
||||||
<div class="movie" (click)="openCurrentMovie(movie.id)">
|
<div class="movie" (click)="openCurrentMovie(movie.id)">
|
||||||
<img
|
<img
|
||||||
[ngClass]="{ selected: movie.id === currentMovie }"
|
[ngClass]="{ selected: movie.id === currentMovie }"
|
||||||
src="{{
|
[src]="getThumbnailUrl(movie.id, movie.file_name)"
|
||||||
environmentBaseUrl +
|
|
||||||
'/media/thumbnails/' +
|
|
||||||
movie.id +
|
|
||||||
'/' +
|
|
||||||
movie.file_name +
|
|
||||||
'_480p.jpg'
|
|
||||||
}}"
|
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import { environment } from '../../../../environments/environment';
|
||||||
export class CategoriesComponent {
|
export class CategoriesComponent {
|
||||||
@Input() movies: any[] = [];
|
@Input() movies: any[] = [];
|
||||||
@Input() currentMovie: number = 0;
|
@Input() currentMovie: number = 0;
|
||||||
|
@Input() favoriteMovies: any[] = [];
|
||||||
@Output() currentMovieId = new EventEmitter<number>();
|
@Output() currentMovieId = new EventEmitter<number>();
|
||||||
|
|
||||||
environmentBaseUrl: string = environment.baseUrl;
|
environmentBaseUrl: string = environment.baseUrl;
|
||||||
|
|
@ -67,6 +68,10 @@ export class CategoriesComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getThumbnailUrl(movieId: number, fileName: string): string {
|
||||||
|
return `${environment.baseUrl}/media/thumbnails/${movieId}/${fileName}_480p.jpg`;
|
||||||
|
}
|
||||||
|
|
||||||
// Category scroll
|
// Category scroll
|
||||||
|
|
||||||
@HostListener('window:resize')
|
@HostListener('window:resize')
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,14 @@ import { UserService } from '../../../../services/user.service';
|
||||||
export class HeroBannerComponent {
|
export class HeroBannerComponent {
|
||||||
@Input() currentMovie: any[] = [];
|
@Input() currentMovie: any[] = [];
|
||||||
@Input() screenWidth: boolean = false;
|
@Input() screenWidth: boolean = false;
|
||||||
|
@Input() favoriteMovies: 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;
|
||||||
}>();
|
}>();
|
||||||
@Output() moviesChange = new EventEmitter<any[]>();
|
@Output() moviesChange = new EventEmitter<any[]>();
|
||||||
|
@Output() favoriteMovieChange = new EventEmitter<any[]>();
|
||||||
|
|
||||||
currentUserLikedMovies: number[] = [];
|
|
||||||
environmentBaseUrl: string = environment.baseUrl;
|
environmentBaseUrl: string = environment.baseUrl;
|
||||||
movieIsUploaded: { [resolution: string]: boolean } = {
|
movieIsUploaded: { [resolution: string]: boolean } = {
|
||||||
'480': false,
|
'480': false,
|
||||||
|
|
@ -42,39 +43,17 @@ export class HeroBannerComponent {
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
toggleLikeMovie(movieId: number): void {
|
||||||
this.loadLikedMovies();
|
if (this.favoriteMovies.includes(movieId)) {
|
||||||
|
this.favoriteMovies = this.favoriteMovies.filter((id) => id !== movieId);
|
||||||
|
} else {
|
||||||
|
this.favoriteMovies.push(movieId);
|
||||||
|
}
|
||||||
|
this.favoriteMovieChange.emit(this.favoriteMovies);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkLikeMovies(videoId: number) {
|
checkLikeMovies(videoId: number) {
|
||||||
return this.currentUserLikedMovies.includes(videoId);
|
return this.favoriteMovies.includes(videoId);
|
||||||
}
|
|
||||||
|
|
||||||
async loadLikedMovies() {
|
|
||||||
try {
|
|
||||||
const likedMovies = await this.userService.getLikedMovies();
|
|
||||||
this.currentUserLikedMovies = likedMovies.liked_videos;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleLikeMovie(movieId: number): void {
|
|
||||||
if (this.currentUserLikedMovies.includes(movieId)) {
|
|
||||||
this.currentUserLikedMovies = this.currentUserLikedMovies.filter(
|
|
||||||
(id) => id !== movieId
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.currentUserLikedMovies.push(movieId);
|
|
||||||
}
|
|
||||||
this.updateLikeMovies();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateLikeMovies() {
|
|
||||||
const body = {
|
|
||||||
liked_videos: this.currentUserLikedMovies,
|
|
||||||
};
|
|
||||||
this.userService.updateLikedMovies(body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue