add loading spinner + actions lock

This commit is contained in:
X4Lo committed 2024-05-11 08:58:54 +01:00
1 parent 70975f77b5
commit 8a08958ae3
3 files changed
+78 -37

No files matched your search

@@ -200,3 +200,16 @@
.movie-card .card-info {
color: #fff;
}
/* ! LOADING OVERLAY */
.loading-overlay {
position: absolute;
inset: 0;
background-color: #4a515798;
z-index: 999;
transition: opacity 0.5s ease-in-out;
}
.loading-overlay .d-flex {
height: 100%;
}
@@ -1,7 +1,15 @@
<div class="movie-card" [@fadeInOut]="direction">
<div class="movie-card" [@fadeInOut]="animationDirection">
<div class="card-head">
<img class="card-img" [src]="postPath" alt="Movie Poster">
<div class="loading-overlay" *ngIf="lockActions" @animateDestroy>
<div class="d-flex justify-content-center align-items-center" style="height: 100%;">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
<div class="card-overlay-2">
<div class="in-library" *ngIf="entry.isInLibrary && isCertainRoute()">
<span class="material-symbols-outlined">
@@ -1,7 +1,7 @@
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 } 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';
@@ -48,13 +48,21 @@ import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.
),
]),
]),
trigger('animateDestroy', [
state('void', style({ opacity: '0' })),
transition('* => void', animate('200ms ease-in')),
state('void', style({ opacity: '0' })),
transition('void => *', animate('200ms ease-in')),
]),
],
})
export class MainCardComponent implements OnInit {
@Output() removedEvent = new EventEmitter();
@Input() entry!: Entry;
direction = 'topToBottom';
lockActions: boolean = false;
animationDirection = 'topToBottom';
constructor(
private libraryService: LibraryService,
@@ -82,7 +90,8 @@ export class MainCardComponent implements OnInit {
'leftToRight',
'rightToLeft',
];
this.direction = directions[Math.floor(Math.random() * directions.length)];
this.animationDirection =
directions[Math.floor(Math.random() * directions.length)];
}
get releaseYear(): number {
@@ -94,24 +103,30 @@ export class MainCardComponent implements OnInit {
}
addEntry(tmdb_id: string, is_tvserie: boolean) {
console.log('Adding Entry To Library.');
// console.log('Adding Entry To Library.');
this.lockActions = true;
let obs = this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
next: (entry) => {
if (entry != null) {
console.log(`Entry added to library`, entry);
// TODO success notification
// console.log(`Entry added to library`, entry);
entry.isInLibrary = true;
this.entry = entry;
this.libraryService.refrechEntries();
this.lockActions = false;
obs.unsubscribe();
}
},
error: (error) => {
// TODO error notification
console.error('Error adding entry:', error);
},
this.lockActions = false;
}
});
}
removeEntry(id: number) {
this.lockActions = true;
const dialogRef = this.dialog.open(ConfirmModalComponent, {
width: '400px',
data: {
@@ -122,42 +137,47 @@ export class MainCardComponent implements OnInit {
});
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);
},
});
if (!result || result.confirmed != true) {
this.lockActions = false;
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);
},
complete: () => {
this.lockActions = false;
},
});
});
}
showAddToListModal() {
if (this.entry) {
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
width: '400px',
height: '55%',
data: {
entryId: this.entry.id,
},
});
if (!this.entry) return;
dialogRef.afterClosed().subscribe((result) => {
console.log('Modal Closed: ', result);
});
}
this.lockActions = true;
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
width: '400px',
height: '55%',
data: {
entryId: this.entry.id,
},
});
dialogRef.afterClosed().subscribe((result) => {
this.lockActions = false;
// console.log('Modal Closed: ', result);
});
}
cardClick() {