fix library not refreching when add new entry
This commit is contained in:
1 parent
f68d5cbb89
commit
561f27b065
4 files changed
+37
-9
No files matched your search
@@ -1,4 +1,3 @@
|
||||
/* Custom CSS to visually connect the elements */
|
||||
.custom-group .form-select {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
@@ -32,7 +31,6 @@
|
||||
margin-right: -1px;
|
||||
}
|
||||
|
||||
/* Adjust the select width as needed */
|
||||
#single-select-field {
|
||||
max-width: 120px;
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||
@@ -58,7 +58,7 @@
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1">
|
||||
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||
|
||||
@@ -1,6 +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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library',
|
||||
@@ -18,22 +19,30 @@ export class LibraryComponent {
|
||||
currentPage: number = 1;
|
||||
pageSize: number = 10;
|
||||
|
||||
constructor(private libraryService: LibraryService) {}
|
||||
constructor(private router: Router, private libraryService: LibraryService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.pageSize = this.getDefaultPageSize();
|
||||
this.fetchEntries();
|
||||
this.getEntries();
|
||||
|
||||
this.router.events.subscribe((event) => {
|
||||
if (event instanceof NavigationEnd && event.url === '/library') {
|
||||
this.pageSize = this.getDefaultPageSize();
|
||||
this.getEntries(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// uses libraryService to get library all content
|
||||
fetchEntries() {
|
||||
this.libraryService.getAllEntries().subscribe({
|
||||
getEntries(forceFetch: boolean = false) {
|
||||
this.libraryService.getAllEntries(forceFetch).subscribe({
|
||||
next: (entries) => {
|
||||
this.entries = entries;
|
||||
this.filterEntries();
|
||||
},
|
||||
error: (error) => {
|
||||
// Handle any errors, possibly informing the user.
|
||||
console.log(`Couldn't get entries.`, error);
|
||||
// TODO show notification
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -51,6 +60,12 @@ export class LibraryComponent {
|
||||
temp = this.entries;
|
||||
}
|
||||
|
||||
// ? sort filter
|
||||
temp = temp.sort(
|
||||
(a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
|
||||
const startIndex = (this.currentPage - 1) * this.pageSize;
|
||||
const endIndex = startIndex + this.pageSize;
|
||||
|
||||
|
||||
Reference in new issue
Block a user