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
@@ -199,4 +199,17 @@
|
|||||||
.movie-card .card-title,
|
.movie-card .card-title,
|
||||||
.movie-card .card-info {
|
.movie-card .card-info {
|
||||||
color: #fff;
|
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">
|
<div class="card-head">
|
||||||
<img class="card-img" [src]="postPath" alt="Movie Poster">
|
<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="card-overlay-2">
|
||||||
<div class="in-library" *ngIf="entry.isInLibrary && isCertainRoute()">
|
<div class="in-library" *ngIf="entry.isInLibrary && isCertainRoute()">
|
||||||
<span class="material-symbols-outlined">
|
<span class="material-symbols-outlined">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
|
import { UserCollectionsModalComponent } from '../../modals/list-selection-modal/user-collections-modal.component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
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 { Entry } from '../../../models/entry.model';
|
||||||
import { LibraryService } from '../../../../core/services/library.service';
|
import { LibraryService } from '../../../../core/services/library.service';
|
||||||
import { Router } from '@angular/router';
|
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 {
|
export class MainCardComponent implements OnInit {
|
||||||
@Output() removedEvent = new EventEmitter();
|
@Output() removedEvent = new EventEmitter();
|
||||||
@Input() entry!: Entry;
|
@Input() entry!: Entry;
|
||||||
|
|
||||||
direction = 'topToBottom';
|
lockActions: boolean = false;
|
||||||
|
|
||||||
|
animationDirection = 'topToBottom';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private libraryService: LibraryService,
|
private libraryService: LibraryService,
|
||||||
@@ -82,7 +90,8 @@ export class MainCardComponent implements OnInit {
|
|||||||
'leftToRight',
|
'leftToRight',
|
||||||
'rightToLeft',
|
'rightToLeft',
|
||||||
];
|
];
|
||||||
this.direction = directions[Math.floor(Math.random() * directions.length)];
|
this.animationDirection =
|
||||||
|
directions[Math.floor(Math.random() * directions.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
get releaseYear(): number {
|
get releaseYear(): number {
|
||||||
@@ -94,24 +103,30 @@ export class MainCardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addEntry(tmdb_id: string, is_tvserie: boolean) {
|
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({
|
let obs = this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
|
||||||
next: (entry) => {
|
next: (entry) => {
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
console.log(`Entry added to library`, entry);
|
// TODO success notification
|
||||||
|
// console.log(`Entry added to library`, entry);
|
||||||
entry.isInLibrary = true;
|
entry.isInLibrary = true;
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.libraryService.refrechEntries();
|
this.libraryService.refrechEntries();
|
||||||
|
this.lockActions = false;
|
||||||
obs.unsubscribe();
|
obs.unsubscribe();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
|
// TODO error notification
|
||||||
console.error('Error adding entry:', error);
|
console.error('Error adding entry:', error);
|
||||||
},
|
this.lockActions = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeEntry(id: number) {
|
removeEntry(id: number) {
|
||||||
|
this.lockActions = true;
|
||||||
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
const dialogRef = this.dialog.open(ConfirmModalComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
data: {
|
data: {
|
||||||
@@ -122,42 +137,47 @@ export class MainCardComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
if (result) {
|
if (!result || result.confirmed != true) {
|
||||||
console.log(result);
|
this.lockActions = false;
|
||||||
if (result.confirmed != true) return;
|
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);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
showAddToListModal() {
|
||||||
if (this.entry) {
|
if (!this.entry) return;
|
||||||
const dialogRef = this.dialog.open(UserCollectionsModalComponent, {
|
|
||||||
width: '400px',
|
|
||||||
height: '55%',
|
|
||||||
data: {
|
|
||||||
entryId: this.entry.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
this.lockActions = true;
|
||||||
console.log('Modal Closed: ', result);
|
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() {
|
cardClick() {
|
||||||
|
|||||||
Reference in new issue
Block a user