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
@@ -0,0 +1,15 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { LibraryService } from '../services/library.service';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class LibraryEntriesResolver implements Resolve<any> {
|
||||||
|
constructor(private libraryService: LibraryService) {}
|
||||||
|
|
||||||
|
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||||
|
return this.libraryService.getAllEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
/* Custom CSS to visually connect the elements */
|
|
||||||
.custom-group .form-select {
|
.custom-group .form-select {
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
@@ -32,7 +31,6 @@
|
|||||||
margin-right: -1px;
|
margin-right: -1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust the select width as needed */
|
|
||||||
#single-select-field {
|
#single-select-field {
|
||||||
max-width: 120px;
|
max-width: 120px;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<!--end breadcrumb-->
|
<!--end breadcrumb-->
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- 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">
|
<ul class="pagination pagination-sm">
|
||||||
<li class="page-item" [class.disabled]="currentPage === 1">
|
<li class="page-item" [class.disabled]="currentPage === 1">
|
||||||
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Entry } from '../../shared/models/entry.model';
|
import { Entry } from '../../shared/models/entry.model';
|
||||||
import { LibraryService } from '../../core/services/library.service';
|
import { LibraryService } from '../../core/services/library.service';
|
||||||
|
import { NavigationEnd, Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-library',
|
selector: 'app-library',
|
||||||
@@ -18,22 +19,30 @@ export class LibraryComponent {
|
|||||||
currentPage: number = 1;
|
currentPage: number = 1;
|
||||||
pageSize: number = 10;
|
pageSize: number = 10;
|
||||||
|
|
||||||
constructor(private libraryService: LibraryService) {}
|
constructor(private router: Router, private libraryService: LibraryService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.pageSize = this.getDefaultPageSize();
|
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
|
// uses libraryService to get library all content
|
||||||
fetchEntries() {
|
getEntries(forceFetch: boolean = false) {
|
||||||
this.libraryService.getAllEntries().subscribe({
|
this.libraryService.getAllEntries(forceFetch).subscribe({
|
||||||
next: (entries) => {
|
next: (entries) => {
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
this.filterEntries();
|
this.filterEntries();
|
||||||
},
|
},
|
||||||
error: (error) => {
|
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;
|
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 startIndex = (this.currentPage - 1) * this.pageSize;
|
||||||
const endIndex = startIndex + this.pageSize;
|
const endIndex = startIndex + this.pageSize;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user