refactor: rename MoviesListComponent to VideoListComponent and update variables accordingly

This commit is contained in:
Chneemann 2025-04-29 04:35:49 +02:00
parent 7e08f6379f
commit 3cd3f44dea
7 changed files with 82 additions and 83 deletions

View file

@ -1,43 +1,42 @@
@if (movies.length > 0) { @if (videos.length > 0) {
<section class="hide-scrollbar"> <section class="hide-scrollbar">
<!-- New movies this week --> <!-- New videos this week -->
@if (recentMovies().length > 0) { @if (recentVideos().length > 0) {
<div class="category"> <div class="category">
<p>New movies added this week</p> <p>New videos added this week</p>
<app-movie-list <app-video-list
[movies]="recentMovies()" [videos]="recentVideos()"
[currentMovie]="currentMovie" [currentVideo]="currentVideo"
[watchedMovies]="watchedMovies" [watchedVideos]="watchedVideos"
(currentMovieId)="openCurrentMovie($event)" (currentVideoId)="openCurrentVideo($event)"
></app-movie-list> ></app-video-list>
</div> </div>
} }
<!-- Favorites --> <!-- Favorites -->
@if (favoriteMovies.length > 0) { @if (favoriteVideos.length > 0) {
<div class="category"> <div class="category">
<p>Favorites</p> <p>Favorites</p>
<app-movie-list <app-video-list
[movies]="getFavoriteMovies()" [videos]="getFavoriteVideos()"
[currentMovie]="currentMovie" [currentVideo]="currentVideo"
[watchedMovies]="watchedMovies" [watchedVideos]="watchedVideos"
(currentMovieId)="openCurrentMovie($event)" (currentVideoId)="openCurrentVideo($event)"
></app-movie-list> ></app-video-list>
</div> </div>
} }
<!-- Genre columns --> <!-- Genre columns -->
@for (filmGenre of filmGenres; track filmGenre) { @for (filmGenre of filmGenres; track filmGenre) {
<!-- Movies by genre --> <!-- Videos by genre -->
@if (getAllMovies(filmGenre.code).length > 0) { @if (getAllVideos(filmGenre.code).length > 0) {
<div class="category"> <div class="category">
<p>{{ filmGenre.name }}</p> <app-video-list
<app-movie-list [videos]="getAllVideos(filmGenre.code)"
[movies]="getAllMovies(filmGenre.code)" [currentVideo]="currentVideo"
[currentMovie]="currentMovie" [watchedVideos]="watchedVideos"
[watchedMovies]="watchedMovies" (currentVideoId)="openCurrentVideo($event)"
(currentMovieId)="openCurrentMovie($event)" ></app-video-list>
></app-movie-list>
</div> </div>
} } } }
</section> </section>

View file

@ -8,21 +8,21 @@ import {
Output, Output,
} from '@angular/core'; } from '@angular/core';
import { environment } from '../../../../environments/environment'; import { environment } from '../../../../environments/environment';
import { MoviesListComponent } from './movie-list/movie-list.component'; import { VideoListComponent } from './video-list/video-list.component';
@Component({ @Component({
selector: 'app-categories', selector: 'app-categories',
standalone: true, standalone: true,
imports: [CommonModule, MoviesListComponent], imports: [CommonModule, VideoListComponent],
templateUrl: './categories.component.html', templateUrl: './categories.component.html',
styleUrl: './categories.component.scss', styleUrl: './categories.component.scss',
}) })
export class CategoriesComponent implements AfterViewInit { export class CategoriesComponent implements AfterViewInit {
@Input() movies: any[] = []; @Input() videos: any[] = [];
@Input() currentMovie: number = 0; @Input() currentVideo: number = 0;
@Input() favoriteMovies: any[] = []; @Input() favoriteVideos: any[] = [];
@Input() watchedMovies: any[] = []; @Input() watchedVideos: any[] = [];
@Output() currentMovieId = new EventEmitter<number>(); @Output() currentVideoId = new EventEmitter<number>();
environmentBaseUrl: string = environment.baseUrl; environmentBaseUrl: string = environment.baseUrl;
isScrollable: boolean = false; isScrollable: boolean = false;
@ -52,31 +52,31 @@ export class CategoriesComponent implements AfterViewInit {
this.checkScroll(); this.checkScroll();
} }
openCurrentMovie(movieId: number) { openCurrentVideo(videoId: number) {
this.currentMovie = movieId; this.currentVideo = videoId;
this.currentMovieId.emit(movieId); this.currentVideoId.emit(videoId);
} }
getAllMovies(filmGenre: string) { getAllVideos(filmGenre: string) {
return this.movies.filter((movie) => movie.film_genre === filmGenre); return this.videos.filter((video) => video.film_genre === filmGenre);
} }
getFavoriteMovies() { getFavoriteVideos() {
return this.movies.filter((movie) => return this.videos.filter((video) =>
this.favoriteMovies.includes(movie.id) this.favoriteVideos.includes(video.id)
); );
} }
recentMovies() { recentVideos() {
const today = new Date(); const today = new Date();
const dayOfWeek = today.getDay(); const dayOfWeek = today.getDay();
const lastMonday = new Date(today); const lastMonday = new Date(today);
lastMonday.setDate(today.getDate() - ((dayOfWeek + 6) % 7)); lastMonday.setDate(today.getDate() - ((dayOfWeek + 6) % 7));
return this.movies.filter((movie) => { return this.videos.filter((video) => {
const movieDate = new Date(movie.created_at); const videoDate = new Date(video.created_at);
return movieDate >= lastMonday && movieDate <= today; return videoDate >= lastMonday && videoDate <= today;
}); });
} }
@ -87,7 +87,7 @@ export class CategoriesComponent implements AfterViewInit {
checkScroll() { checkScroll() {
const containers = document.querySelectorAll( const containers = document.querySelectorAll(
'.movies' '.videos'
) as NodeListOf<HTMLElement>; ) as NodeListOf<HTMLElement>;
containers.forEach((container) => { containers.forEach((container) => {
const scrollButtons = container.parentElement?.querySelector( const scrollButtons = container.parentElement?.querySelector(

View file

@ -1,15 +1,15 @@
<div class="movies"> <div class="videos">
<!-- List of movies --> <!-- List of videos -->
@for (movie of movies; track movie) { @for (video of videos; track video) {
<div class="movie" (click)="openCurrentMovie(movie.id)"> <div class="video" (click)="openCurrentVideo(video.id)">
<div class="banner"> <div class="banner">
<img <img
[ngClass]="{ selected: movie.id === currentMovie }" [ngClass]="{ selected: video.id === currentVideo }"
[src]="getThumbnailUrl(movie.id, movie.file_name)" [src]="getThumbnailUrl(video.id, video.file_name)"
alt="" alt=""
/> />
</div> </div>
<div *ngIf="watchedMovies.includes(movie.id)" class="watched"> <div *ngIf="watchedVideos.includes(video.id)" class="watched">
<img src="./assets/img/open-eye.svg" alt="" /> <img src="./assets/img/open-eye.svg" alt="" />
</div> </div>
</div> </div>

View file

@ -1,6 +1,6 @@
@use "./../../../../../assets/style/colors.scss" as *; @use "./../../../../../assets/style/colors.scss" as *;
.movies { .videos {
display: flex; display: flex;
overflow-x: auto; overflow-x: auto;
overflow-y: hidden; overflow-y: hidden;
@ -9,11 +9,11 @@
padding-bottom: 24px; padding-bottom: 24px;
} }
.movies::-webkit-scrollbar { .videos::-webkit-scrollbar {
display: none; display: none;
} }
.movie { .video {
position: relative; position: relative;
width: 213px; width: 213px;
height: 120px; height: 120px;

View file

@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MoviesListComponent } from './movie-list.component'; import { VideoListComponent } from './video-list.component';
describe('MoviesListComponent', () => { describe('VideoListComponent', () => {
let component: MoviesListComponent; let component: VideoListComponent;
let fixture: ComponentFixture<MoviesListComponent>; let fixture: ComponentFixture<VideoListComponent>;
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [MoviesListComponent], imports: [VideoListComponent],
}).compileComponents(); }).compileComponents();
fixture = TestBed.createComponent(MoviesListComponent); fixture = TestBed.createComponent(VideoListComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });

View file

@ -3,33 +3,33 @@ import { environment } from '../../../../../environments/environment';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@Component({ @Component({
selector: 'app-movie-list', selector: 'app-video-list',
standalone: true, standalone: true,
imports: [CommonModule], imports: [CommonModule],
templateUrl: './movie-list.component.html', templateUrl: './video-list.component.html',
styleUrls: ['./movie-list.component.scss'], styleUrls: ['./video-list.component.scss'],
}) })
export class MoviesListComponent { export class VideoListComponent {
@Input() movies: any[] = []; @Input() videos: any[] = [];
@Input() currentMovie: number = 0; @Input() currentVideo: number = 0;
@Input() watchedMovies: any[] = []; @Input() watchedVideos: any[] = [];
@Input() movieCategory: string = ''; @Input() videoCategory: string = '';
@Output() currentMovieId = new EventEmitter<number>(); @Output() currentVideoId = new EventEmitter<number>();
getThumbnailUrl(movieId: number, fileName: string): string { getThumbnailUrl(videoId: number, fileName: string): string {
return `${environment.baseUrl}/media/thumbnails/${movieId}/${fileName}_480p.jpg`; return `${environment.baseUrl}/media/thumbnails/${videoId}/${fileName}_480p.jpg`;
} }
openCurrentMovie(movieId: number) { openCurrentVideo(videoId: number) {
this.currentMovie = movieId; this.currentVideo = videoId;
this.currentMovieId.emit(movieId); this.currentVideoId.emit(videoId);
} }
scrollLeft(event: MouseEvent) { scrollLeft(event: MouseEvent) {
const button = event.target as HTMLElement; const button = event.target as HTMLElement;
const container = button const container = button
.closest('.category') .closest('.category')
?.querySelector('.movies') as HTMLElement; ?.querySelector('.videos') as HTMLElement;
if (container) { if (container) {
container.scrollLeft -= 217; container.scrollLeft -= 217;
} }
@ -39,7 +39,7 @@ export class MoviesListComponent {
const button = event.target as HTMLElement; const button = event.target as HTMLElement;
const container = button const container = button
.closest('.category') .closest('.category')
?.querySelector('.movies') as HTMLElement; ?.querySelector('.videos') as HTMLElement;
if (container) { if (container) {
container.scrollLeft += 217; container.scrollLeft += 217;
} }

View file

@ -30,11 +30,11 @@
*ngIf=" *ngIf="
this.isWideScreen() || (!this.isWideScreen() && currentMovie.length === 0) this.isWideScreen() || (!this.isWideScreen() && currentMovie.length === 0)
" "
[movies]="movies" [videos]="movies"
[currentMovie]="currentMovie[0]?.id" [currentVideo]="currentMovie[0]?.id"
[favoriteMovies]="favoriteMovies" [favoriteVideos]="favoriteMovies"
[watchedMovies]="watchedMovies" [watchedVideos]="watchedMovies"
(currentMovieId)="currentMovieId($event)" (currentVideoId)="currentMovieId($event)"
></app-categories> ></app-categories>
} @else { } @else {
<div class="video-overlay"> <div class="video-overlay">