diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.html b/frontend/src/app/shared/components/cards/main-card/main-card.component.html index 9125ca7..8c246b7 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.html +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.html @@ -1,6 +1,6 @@
- Movie Poster + Movie Poster
diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts index 7f0cd3a..3cd2491 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts @@ -1,7 +1,13 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component'; import { MatDialog } from '@angular/material/dialog'; -import { trigger, transition, style, animate, state } from '@angular/animations'; +import { + trigger, + transition, + style, + animate, + state, +} from '@angular/animations'; import { Entry } from '../../../models/entry.model'; import { LibraryService } from '../../../../core/services/library.service'; import { Router } from '@angular/router'; @@ -57,7 +63,8 @@ import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal. ], }) export class MainCardComponent implements OnInit { - @Output() removedEvent = new EventEmitter(); + @Output() onEntryRemove = new EventEmitter(); + @Output() onEntryUpdate = new EventEmitter(); @Input() entry!: Entry; lockActions: boolean = false; @@ -71,15 +78,17 @@ export class MainCardComponent implements OnInit { ) {} ngOnInit(): void { - this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({ - next: (e) => { - if (e != null) { - e.isInLibrary = true; - this.entry = e; - } - }, - error: (error) => {}, - }); + if (!this.entry.isInLibrary) { + this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({ + next: (e) => { + if (e != null) { + e.isInLibrary = true; + this.entry = e; + } + }, + error: (error) => {}, + }); + } this.setRandomDirection(); } @@ -112,7 +121,8 @@ export class MainCardComponent implements OnInit { // console.log(`Entry added to library`, entry); entry.isInLibrary = true; this.entry = entry; - this.libraryService.refrechEntries(); + this.libraryService.refrechEntries().subscribe(); + this.onEntryUpdate.emit(this.entry.id); this.lockActions = false; obs.unsubscribe(); } @@ -121,7 +131,7 @@ export class MainCardComponent implements OnInit { // TODO error notification console.error('Error adding entry:', error); this.lockActions = false; - } + }, }); } @@ -148,7 +158,8 @@ export class MainCardComponent implements OnInit { // ? emit to dynamic entry list this.entry.id = 0; this.entry.isInLibrary = false; - this.removedEvent.emit(this.entry.id); + this.onEntryRemove.emit(this.entry.id); + this.libraryService.refrechEntries().subscribe(); // todo entry removed notification }, error: (error) => { @@ -203,11 +214,34 @@ export class MainCardComponent implements OnInit { ); } - get postPath() { - if (this.entry.poster_path == null) - return 'assets/images/default/default-poster.png'; + get posterPath() { + // * Not in library, use TMDB poster + if (!this.entry.isInLibrary) + return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path; - return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path; + // * Is in library: use a local poster + if (this.entry.medias) { + const selectedPosters = this.entry.medias.filter( + (m) => m.type == 'poster' && m.is_selected + ); + + if ( + selectedPosters.length && + selectedPosters[0] && + selectedPosters[0].path + ) { + const name = selectedPosters[0].path.split('.')[0]; + const extention = selectedPosters[0].path.split('.')[1]; + return `http://localhost:4000/api/v1/media/entries/posters/${name}_preview.${extention}`; + } + } + + // * No local poster available, Use TMDB poster + if (this.entry.poster_path) + return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path; + + // * No poster found, use default poster image as a last stand + return 'assets/images/default/default-poster.png'; } get runtime() {