more animations + remove confirm for main entry card

This commit is contained in:
X4Lo committed 2024-05-10 10:23:04 +01:00
1 parent ff76e3900b
commit 05e4505fdb
2 files changed
+67 -16

No files matched your search

@@ -1,4 +1,4 @@
<div class="movie-card" @fadeInOut>
<div class="movie-card" [@fadeInOut]="direction">
<div class="card-head">
<img class="card-img" [src]="postPath" alt="Movie Poster">
@@ -35,8 +35,8 @@
</a>
<div class="card-info">
<span class="Year">{{releaseYear}}</span>
<i class="card-dot"></i>
<span class="duration">{{runtime}} min</span>
<i class="card-dot" *ngIf="runtime"></i>
<span class="duration" *ngIf="runtime">{{runtime}} min</span>
</div>
</div>
</div>
@@ -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,7 +112,20 @@ export class MainCardComponent implements OnInit {
}
removeEntry(id: number) {
console.log('Deleting Entry From Library.');
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);
@@ -93,10 +136,13 @@ export class MainCardComponent implements OnInit {
// todo entry removed notification
},
error: (error) => {
// TODO show notification
console.error('Error deleting entry:', error);
},
});
}
});
}
showAddToListModal() {
if (this.entry) {
@@ -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() {