fix entry card not disapearing after remove from library
This commit is contained in:
1 parent
561f27b065
commit
42726c5881
4 files changed
+43
-8
No files matched your search
@@ -54,7 +54,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<app-dynamic-entry-list [entries]="entriesToShow"></app-dynamic-entry-list>
|
||||
<app-dynamic-entry-list [entries]="entriesToShow" (removedEvent)="entryRemoved($event)"></app-dynamic-entry-list>
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
<!-- Entries Container/Grid -->
|
||||
<div class="movies-container">
|
||||
<app-main-card *ngFor="let entry of entries" [entry]="entry"></app-main-card>
|
||||
<ng-container *ngFor="let entry of entries">
|
||||
<app-main-card [entry]="entry" (removedEvent)="entryRemoved($event)" @animateDestroy></app-main-card>
|
||||
</ng-container>
|
||||
</div>
|
||||
+21
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user