add local poster to main card
This commit is contained in:
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="movie-card" [@fadeInOut]="animationDirection">
|
||||||
<div class="card-head">
|
<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="loading-overlay" *ngIf="lockActions" @animateDestroy>
|
||||||
<div class="d-flex justify-content-center align-items-center" style="height: 100%;">
|
<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 { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
|
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
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 { Entry } from '../../../models/entry.model';
|
||||||
import { LibraryService } from '../../../../core/services/library.service';
|
import { LibraryService } from '../../../../core/services/library.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
@@ -57,7 +63,8 @@ import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class MainCardComponent implements OnInit {
|
export class MainCardComponent implements OnInit {
|
||||||
@Output() removedEvent = new EventEmitter();
|
@Output() onEntryRemove = new EventEmitter();
|
||||||
|
@Output() onEntryUpdate = new EventEmitter();
|
||||||
@Input() entry!: Entry;
|
@Input() entry!: Entry;
|
||||||
|
|
||||||
lockActions: boolean = false;
|
lockActions: boolean = false;
|
||||||
@@ -71,15 +78,17 @@ export class MainCardComponent implements OnInit {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
|
if (!this.entry.isInLibrary) {
|
||||||
next: (e) => {
|
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
|
||||||
if (e != null) {
|
next: (e) => {
|
||||||
e.isInLibrary = true;
|
if (e != null) {
|
||||||
this.entry = e;
|
e.isInLibrary = true;
|
||||||
}
|
this.entry = e;
|
||||||
},
|
}
|
||||||
error: (error) => {},
|
},
|
||||||
});
|
error: (error) => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
this.setRandomDirection();
|
this.setRandomDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +121,8 @@ export class MainCardComponent implements OnInit {
|
|||||||
// console.log(`Entry added to library`, entry);
|
// console.log(`Entry added to library`, entry);
|
||||||
entry.isInLibrary = true;
|
entry.isInLibrary = true;
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.libraryService.refrechEntries();
|
this.libraryService.refrechEntries().subscribe();
|
||||||
|
this.onEntryUpdate.emit(this.entry.id);
|
||||||
this.lockActions = false;
|
this.lockActions = false;
|
||||||
obs.unsubscribe();
|
obs.unsubscribe();
|
||||||
}
|
}
|
||||||
@@ -121,7 +131,7 @@ export class MainCardComponent implements OnInit {
|
|||||||
// TODO error notification
|
// TODO error notification
|
||||||
console.error('Error adding entry:', error);
|
console.error('Error adding entry:', error);
|
||||||
this.lockActions = false;
|
this.lockActions = false;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +158,8 @@ export class MainCardComponent implements OnInit {
|
|||||||
// ? emit to dynamic entry list
|
// ? emit to dynamic entry list
|
||||||
this.entry.id = 0;
|
this.entry.id = 0;
|
||||||
this.entry.isInLibrary = false;
|
this.entry.isInLibrary = false;
|
||||||
this.removedEvent.emit(this.entry.id);
|
this.onEntryRemove.emit(this.entry.id);
|
||||||
|
this.libraryService.refrechEntries().subscribe();
|
||||||
// todo entry removed notification
|
// todo entry removed notification
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
@@ -203,11 +214,34 @@ export class MainCardComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get postPath() {
|
get posterPath() {
|
||||||
if (this.entry.poster_path == null)
|
// * Not in library, use TMDB poster
|
||||||
return 'assets/images/default/default-poster.png';
|
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() {
|
get runtime() {
|
||||||
|
|||||||
Reference in new issue
Block a user