add local poster to main card

This commit is contained in:
X4Lo committed 2024-05-18 15:30:04 +01:00
1 parent 16b86b4ca5
commit 04965e9123
2 files changed
+53 -19

No files matched your search

@@ -1,6 +1,6 @@
<div class="movie-card" [@fadeInOut]="animationDirection">
<div class="card-head">
<img class="card-img" [src]="postPath" alt="Movie Poster">
<img class="card-img" [src]="posterPath" alt="Movie Poster">
<div class="loading-overlay" *ngIf="lockActions" @animateDestroy>
<div class="d-flex justify-content-center align-items-center" style="height: 100%;">
@@ -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() {