From 8a08958ae37a1ad9d5a0a184c158092086b82e4f Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sat, 11 May 2024 08:58:54 +0100 Subject: [PATCH] add loading spinner + actions lock --- .../cards/main-card/main-card.component.css | 13 +++ .../cards/main-card/main-card.component.html | 10 +- .../cards/main-card/main-card.component.ts | 92 +++++++++++-------- 3 files changed, 78 insertions(+), 37 deletions(-) diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.css b/frontend/src/app/shared/components/cards/main-card/main-card.component.css index dfb1f35..5944e92 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.css +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.css @@ -199,4 +199,17 @@ .movie-card .card-title, .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%; } \ No newline at end of file diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.html b/frontend/src/app/shared/components/cards/main-card/main-card.component.html index f93a397..9125ca7 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.html +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.html @@ -1,7 +1,15 @@ -
+
Movie Poster +
+
+
+ Loading... +
+
+
+
diff --git a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts index e838f13..7f0cd3a 100644 --- a/frontend/src/app/shared/components/cards/main-card/main-card.component.ts +++ b/frontend/src/app/shared/components/cards/main-card/main-card.component.ts @@ -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() {