From 42726c5881c9ce03270383e07a92d5c2d5d6b340 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sun, 28 Apr 2024 22:03:24 +0100 Subject: [PATCH] fix entry card not disapearing after remove from library --- .../features/library/library.component.html | 2 +- .../app/features/library/library.component.ts | 23 +++++++++++++++---- .../dynamic-entry-list.component.html | 4 +++- .../dynamic-entry-list.component.ts | 22 +++++++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/features/library/library.component.html b/frontend/src/app/features/library/library.component.html index 33d2bfe..c36d32f 100644 --- a/frontend/src/app/features/library/library.component.html +++ b/frontend/src/app/features/library/library.component.html @@ -54,7 +54,7 @@ - + diff --git a/frontend/src/app/features/library/library.component.ts b/frontend/src/app/features/library/library.component.ts index 254a7eb..8c60a81 100644 --- a/frontend/src/app/features/library/library.component.ts +++ b/frontend/src/app/features/library/library.component.ts @@ -1,7 +1,7 @@ import { Component } from '@angular/core'; import { Entry } from '../../shared/models/entry.model'; import { LibraryService } from '../../core/services/library.service'; -import { NavigationEnd, Router } from '@angular/router'; +import { Event, NavigationEnd, Router } from '@angular/router'; @Component({ selector: 'app-library', @@ -23,7 +23,7 @@ export class LibraryComponent { ngOnInit() { this.pageSize = this.getDefaultPageSize(); - this.getEntries(); + this.getEntries(true); this.router.events.subscribe((event) => { if (event instanceof NavigationEnd && event.url === '/library') { @@ -33,7 +33,7 @@ export class LibraryComponent { }); } - // uses libraryService to get library all content + // ? uses libraryService to get library all entries getEntries(forceFetch: boolean = false) { this.libraryService.getAllEntries(forceFetch).subscribe({ next: (entries) => { @@ -66,14 +66,25 @@ export class LibraryComponent { new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime() ); + this.entriesCount = temp.length; + this.maxPage = Math.ceil(this.entriesCount / this.pageSize); + if (this.currentPage > this.maxPage) this.currentPage = this.maxPage; // fix for when 1 entry in the last page is removed + const startIndex = (this.currentPage - 1) * this.pageSize; const endIndex = startIndex + this.pageSize; - this.entriesCount = temp.length; - this.maxPage = Math.ceil(this.entriesCount / this.pageSize); this.entriesToShow = temp.slice(startIndex, endIndex); } + entryRemoved(event: Event) { + this.entries = this.entries.filter( + (e) => e.id.toString() != event.toString() + ); + this.pageSize = this.getDefaultPageSize(); + this.filterEntries(); + // this.getEntries(true); + } + // ? pagination goToPage(page: number) { this.currentPage = page; @@ -118,7 +129,9 @@ export class LibraryComponent { this.filterEntries(); } + // ? getters getDefaultPageSize() { + // TODO get default page size from settings service return 20; } } diff --git a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.html b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.html index 19966f2..65630a8 100644 --- a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.html +++ b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.html @@ -1,4 +1,6 @@
- + + +
\ No newline at end of file diff --git a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts index 193685b..efc6916 100644 --- a/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts +++ b/frontend/src/app/shared/components/lists/dynamic-entry-list/dynamic-entry-list.component.ts @@ -1,11 +1,31 @@ -import { Component, Input } from '@angular/core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Entry } from '../../../../shared/models/entry.model'; +import { Event } from '@angular/router'; +import { + animate, + state, + style, + transition, + trigger, +} from '@angular/animations'; @Component({ selector: 'app-dynamic-entry-list', templateUrl: './dynamic-entry-list.component.html', styleUrls: ['./dynamic-entry-list.component.css'], + animations: [ + trigger('animateDestroy', [ + state('void', style({ opacity: '0' })), + transition('* => void', animate('500ms ease')), + ]), + ], }) export class DynamicEntryListComponent { + @Output() removedEvent = new EventEmitter(); @Input() entries: Entry[] = []; + + entryRemoved(event: Event) { + // ? emit (entry removed) to library + this.removedEvent.emit(event); + } }