118 lines
3.2 KiB
TypeScript
118 lines
3.2 KiB
TypeScript
import { Component, Input, OnInit } from '@angular/core';
|
|
import { ListSelectionModalComponent } from '../../modals/list-selection-modal/list-selection-modal.component';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { trigger, transition, style, animate } from '@angular/animations';
|
|
import { Entry } from '../../../models/entry.model';
|
|
import { LibraryService } from '../../../../core/services/library.service';
|
|
|
|
@Component({
|
|
selector: 'app-main-card',
|
|
templateUrl: './main-card.component.html',
|
|
styleUrls: ['./main-card.component.css'],
|
|
animations: [
|
|
trigger('fadeInOut', [
|
|
transition(':enter', [
|
|
// :enter is alias for 'void => *'
|
|
style({ opacity: 0 }),
|
|
animate('0.5s ease-out', style({ opacity: 1 })),
|
|
]),
|
|
transition(':leave', [
|
|
// :leave is alias for '* => void'
|
|
animate('0.5s ease-in', style({ opacity: 0 })),
|
|
]),
|
|
]),
|
|
],
|
|
})
|
|
export class MainCardComponent implements OnInit {
|
|
@Input() entry!: Entry;
|
|
|
|
constructor(
|
|
private libraryService: LibraryService,
|
|
public dialog: MatDialog
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
|
|
next: (e) => {
|
|
if (e != null) {
|
|
e.isInLibrary = true;
|
|
this.entry = e;
|
|
}
|
|
},
|
|
error: (error) => {},
|
|
});
|
|
}
|
|
|
|
get releaseYear(): number {
|
|
return new Date(this.entry.release_date).getFullYear();
|
|
}
|
|
|
|
get formattedRate(): string {
|
|
return this.entry.entryRating.tmdb_rating.toFixed(1);
|
|
}
|
|
|
|
addEntry(tmdb_id: string, is_tvserie: boolean) {
|
|
console.log('Adding Entry To Library.');
|
|
this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
|
|
next: (entry) => {
|
|
if (entry != null) {
|
|
entry.isInLibrary = true;
|
|
this.entry = entry;
|
|
this.libraryService.getAllEntries(true);
|
|
}
|
|
},
|
|
error: (error) => {
|
|
console.error('Error adding entry:', error);
|
|
},
|
|
});
|
|
}
|
|
|
|
removeEntry(id: number) {
|
|
console.log('Deleting Entry From Library.');
|
|
this.libraryService.deleteEntry(id).subscribe({
|
|
next: (response) => {
|
|
// Handle successful deletion
|
|
console.log('Entry successfully deleted.', response);
|
|
this.entry.id = 0;
|
|
this.entry.isInLibrary = false;
|
|
},
|
|
error: (error) => {
|
|
// Handle error scenario
|
|
console.error('Error deleting entry:', error);
|
|
// Optionally, display an error message to the user using a service or a component
|
|
},
|
|
});
|
|
}
|
|
|
|
showAddToListModal() {
|
|
if (this.entry) {
|
|
const dialogRef = this.dialog.open(ListSelectionModalComponent, {
|
|
width: '400px',
|
|
height: '55%',
|
|
data: {
|
|
entryId: this.entry.id,
|
|
},
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
console.log('Modal Closed: ', result);
|
|
});
|
|
}
|
|
}
|
|
|
|
cardClick() {
|
|
console.log(this.entry);
|
|
}
|
|
|
|
getTmdbLink() {
|
|
let type = this.entry.is_tvseries ? 'tv' : 'movie';
|
|
return `https://www.themoviedb.org/${type}/${this.entry.entryId.tmdb_id}`;
|
|
}
|
|
|
|
getPostPath() {
|
|
if (this.entry.poster_path == null) return 'assets/images/default/default-poster.png';
|
|
|
|
return `https://image.tmdb.org/t/p/w500` + this.entry.poster_path;
|
|
}
|
|
}
|