more animations + remove confirm for main entry card
This commit is contained in:
1 parent
ff76e3900b
commit
05e4505fdb
2 files changed
+78
-27
No files matched your search
@@ -1,16 +1,11 @@
|
||||
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 } from '@angular/animations';
|
||||
import { Entry } from '../../../models/entry.model';
|
||||
import { LibraryService } from '../../../../core/services/library.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-main-card',
|
||||
@@ -18,16 +13,37 @@ import { Router } from '@angular/router';
|
||||
styleUrls: ['./main-card.component.css'],
|
||||
animations: [
|
||||
trigger('fadeInOut', [
|
||||
transition(':enter', [
|
||||
style({ opacity: 0, transform: 'translateY(-50px)' }),
|
||||
transition('void => topToBottom', [
|
||||
style({ opacity: 0, transform: 'translateY(-50%)' }),
|
||||
animate(
|
||||
'300ms ease-out',
|
||||
style({ opacity: 1, transform: 'translateY(0)' })
|
||||
),
|
||||
]),
|
||||
transition(':leave', [
|
||||
transition('void => bottomToTop', [
|
||||
style({ opacity: 0, transform: 'translateY(50%)' }),
|
||||
animate(
|
||||
'300ms ease-in',
|
||||
'400ms ease-out',
|
||||
style({ opacity: 1, transform: 'translateY(0)' })
|
||||
),
|
||||
]),
|
||||
transition('void => leftToRight', [
|
||||
style({ opacity: 0, transform: 'translateX(-50%)' }),
|
||||
animate(
|
||||
'500ms ease-out',
|
||||
style({ opacity: 1, transform: 'translateX(0)' })
|
||||
),
|
||||
]),
|
||||
transition('void => rightToLeft', [
|
||||
style({ opacity: 0, transform: 'translateX(50%)' }),
|
||||
animate(
|
||||
'500ms ease-out',
|
||||
style({ opacity: 1, transform: 'translateX(0)' })
|
||||
),
|
||||
]),
|
||||
transition('* => void', [
|
||||
animate(
|
||||
'400ms ease-in',
|
||||
style({ opacity: 0, transform: 'translateY(-50px)' })
|
||||
),
|
||||
]),
|
||||
@@ -38,6 +54,8 @@ export class MainCardComponent implements OnInit {
|
||||
@Output() removedEvent = new EventEmitter();
|
||||
@Input() entry!: Entry;
|
||||
|
||||
direction = 'topToBottom';
|
||||
|
||||
constructor(
|
||||
private libraryService: LibraryService,
|
||||
public dialog: MatDialog,
|
||||
@@ -54,6 +72,17 @@ export class MainCardComponent implements OnInit {
|
||||
},
|
||||
error: (error) => {},
|
||||
});
|
||||
this.setRandomDirection();
|
||||
}
|
||||
|
||||
setRandomDirection() {
|
||||
const directions = [
|
||||
'topToBottom',
|
||||
'bottomToTop',
|
||||
'leftToRight',
|
||||
'rightToLeft',
|
||||
];
|
||||
this.direction = directions[Math.floor(Math.random() * directions.length)];
|
||||
}
|
||||
|
||||
get releaseYear(): number {
|
||||
@@ -72,6 +101,7 @@ export class MainCardComponent implements OnInit {
|
||||
console.log(`Entry added to library`, entry);
|
||||
entry.isInLibrary = true;
|
||||
this.entry = entry;
|
||||
this.libraryService.refrechEntries();
|
||||
obs.unsubscribe();
|
||||
}
|
||||
},
|
||||
@@ -82,20 +112,36 @@ export class MainCardComponent implements OnInit {
|
||||
}
|
||||
|
||||
removeEntry(id: number) {
|
||||
console.log('Deleting Entry From Library.');
|
||||
this.libraryService.deleteEntry(id).subscribe({
|
||||
next: (response) => {
|
||||
console.log('Entry successfully deleted.', response);
|
||||
// ? emit to dynamic entry list
|
||||
this.entry.id = 0;
|
||||
this.entry.isInLibrary = false;
|
||||
this.removedEvent.emit(this.entry.id);
|
||||
// todo entry removed notification
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error deleting entry:', error);
|
||||
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||
width: '400px',
|
||||
data: {
|
||||
title: 'Confirmation',
|
||||
message: `Are you sure you want to remove ${this.entry.title} from the library?`,
|
||||
type: 'danger',
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
if (result) {
|
||||
console.log(result);
|
||||
if (result.confirmed != true) return;
|
||||
|
||||
this.libraryService.deleteEntry(id).subscribe({
|
||||
next: (response) => {
|
||||
console.log('Entry successfully deleted.', response);
|
||||
// ? emit to dynamic entry list
|
||||
this.entry.id = 0;
|
||||
this.entry.isInLibrary = false;
|
||||
this.removedEvent.emit(this.entry.id);
|
||||
// todo entry removed notification
|
||||
},
|
||||
error: (error) => {
|
||||
// TODO show notification
|
||||
console.error('Error deleting entry:', error);
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showAddToListModal() {
|
||||
@@ -117,6 +163,11 @@ export class MainCardComponent implements OnInit {
|
||||
cardClick() {
|
||||
if (this.entry.isInLibrary)
|
||||
this.router.navigate([`/entries/${this.entry.id}`]);
|
||||
else
|
||||
window.open(
|
||||
'https://www.themoviedb.org/movie/' + this.entry.entryId.tmdb_id,
|
||||
'_blank'
|
||||
);
|
||||
}
|
||||
|
||||
getTmdbLink() {
|
||||
@@ -136,7 +187,7 @@ export class MainCardComponent implements OnInit {
|
||||
if (this.entry.poster_path == null)
|
||||
return 'assets/images/default/default-poster.png';
|
||||
|
||||
return `https://image.tmdb.org/t/p/w154` + this.entry.poster_path;
|
||||
return `https://image.tmdb.org/t/p/w300` + this.entry.poster_path;
|
||||
}
|
||||
|
||||
get runtime() {
|
||||
|
||||
Reference in new issue
Block a user