add loading spinner + actions lock
This commit is contained in:
1 parent
70975f77b5
commit
8a08958ae3
3 files changed
+78
-37
No files matched your search
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user