refactor: rename GenreService to FilmGenreService and create FilmGenre interface
This commit is contained in:
parent
6bfd167122
commit
58110bc7c1
4 changed files with 20 additions and 32 deletions
|
|
@ -27,8 +27,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- Genre columns -->
|
<!-- Genre columns -->
|
||||||
@for (filmGenre of filmGenres; track filmGenre) {
|
@if (genres$ | async; as genres) {
|
||||||
<!-- Videos by genre -->
|
|
||||||
|
<!-- Loop through genres -->
|
||||||
|
@for (filmGenre of genres; track filmGenre) {
|
||||||
|
|
||||||
|
<!-- If genre has videos -->
|
||||||
@if (getAllVideos(filmGenre.code).length > 0) {
|
@if (getAllVideos(filmGenre.code).length > 0) {
|
||||||
<div class="category">
|
<div class="category">
|
||||||
<p>{{ filmGenre.name }}</p>
|
<p>{{ filmGenre.name }}</p>
|
||||||
|
|
@ -39,6 +43,8 @@
|
||||||
(currentVideoId)="openCurrentVideo($event)"
|
(currentVideoId)="openCurrentVideo($event)"
|
||||||
></app-video-list>
|
></app-video-list>
|
||||||
</div>
|
</div>
|
||||||
} }
|
} } } @else {
|
||||||
|
<div class="category"><p>Loading...</p></div>
|
||||||
|
}
|
||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,9 @@ import {
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { environment } from '../../../../environments/environment';
|
import { environment } from '../../../../environments/environment';
|
||||||
import { VideoListComponent } from './video-list/video-list.component';
|
import { VideoListComponent } from './video-list/video-list.component';
|
||||||
import { FilmGenre, GenreService } from '../../../services/genre.service';
|
import { FilmGenreService } from '../../../services/film-genre.service';
|
||||||
import { Subject, takeUntil } from 'rxjs';
|
import { Subject, takeUntil } from 'rxjs';
|
||||||
|
import { FilmGenre } from '../../../interfaces/film-genre.interface';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-categories',
|
selector: 'app-categories',
|
||||||
|
|
@ -20,7 +21,7 @@ import { Subject, takeUntil } from 'rxjs';
|
||||||
templateUrl: './categories.component.html',
|
templateUrl: './categories.component.html',
|
||||||
styleUrl: './categories.component.scss',
|
styleUrl: './categories.component.scss',
|
||||||
})
|
})
|
||||||
export class CategoriesComponent implements OnInit, AfterViewInit {
|
export class CategoriesComponent implements AfterViewInit {
|
||||||
@Input() videos: any[] = [];
|
@Input() videos: any[] = [];
|
||||||
@Input() currentVideo: number = 0;
|
@Input() currentVideo: number = 0;
|
||||||
@Input() favoriteVideos: any[] = [];
|
@Input() favoriteVideos: any[] = [];
|
||||||
|
|
@ -29,34 +30,15 @@ export class CategoriesComponent implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
environmentBaseUrl: string = environment.baseUrl;
|
environmentBaseUrl: string = environment.baseUrl;
|
||||||
isScrollable: boolean = false;
|
isScrollable: boolean = false;
|
||||||
filmGenres: FilmGenre[] = [];
|
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
genres$ = this.filmGenreService.getGenres();
|
||||||
|
|
||||||
constructor(private genreService: GenreService) {}
|
constructor(private filmGenreService: FilmGenreService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.getFilmGenreNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.checkScroll();
|
this.checkScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.destroy$.next();
|
|
||||||
this.destroy$.complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
getFilmGenreNames(): void {
|
|
||||||
this.genreService
|
|
||||||
.getGenres()
|
|
||||||
.pipe(takeUntil(this.destroy$))
|
|
||||||
.subscribe((genres) => {
|
|
||||||
this.filmGenres = genres;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
openCurrentVideo(videoId: number) {
|
openCurrentVideo(videoId: number) {
|
||||||
this.currentVideo = videoId;
|
this.currentVideo = videoId;
|
||||||
this.currentVideoId.emit(videoId);
|
this.currentVideoId.emit(videoId);
|
||||||
|
|
|
||||||
4
frontend/src/app/interfaces/film-genre.interface.ts
Normal file
4
frontend/src/app/interfaces/film-genre.interface.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface FilmGenre {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,12 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable, of, tap } from 'rxjs';
|
import { Observable, of, tap } from 'rxjs';
|
||||||
import { ApiService } from './api.service';
|
import { ApiService } from './api.service';
|
||||||
|
import { FilmGenre } from '../interfaces/film-genre.interface';
|
||||||
export interface FilmGenre {
|
|
||||||
code: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class GenreService {
|
export class FilmGenreService {
|
||||||
private genres: FilmGenre[] = [];
|
private genres: FilmGenre[] = [];
|
||||||
|
|
||||||
constructor(private apiService: ApiService) {}
|
constructor(private apiService: ApiService) {}
|
||||||
Loading…
Reference in a new issue