watchlist auto refrech

This commit is contained in:
X4Lo committed 2024-05-10 10:17:17 +01:00
1 parent ea5289dc67
commit 60faa34363
2 files changed
+76 -49

No files matched your search

@@ -1,6 +1,6 @@
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Watchlist</div>
<div class="breadcrumb-title pe-3">Library</div>
<div class="ps-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0 p-0">
@@ -12,32 +12,20 @@
</ol>
</nav>
</div>
<div class="ms-auto">
<div class="input-group custom-group">
<div class="input-group-text">Show</div>
<select class="form-select" id="single-select-field" data-placeholder="Choose one thing" style="max-width: 150px;"
[(ngModel)]="pageSize" (change)="setPageSize($event)">
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
<div class="btn-group">
<button type="button" class="btn btn-outline-dark left-btn" [class.active]="entryType === 0"
(click)="setEntryType(0)">All</button>
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === 1"
(click)="setEntryType(1)">Movies</button>
<button type="button" class="btn btn-outline-dark right-btn" [class.active]="entryType === 2"
(click)="setEntryType(2)">TV-Series</button>
</div>
</div>
</div>
</div>
<!--end breadcrumb-->
<div class="d-flex align-items-baseline gap-3">
<div class="product-count d-flex align-items-center gap-3 gap-lg-4 mb-4 fw-medium flex-wrap font-text1">
<a href="javascript:;" (click)="onEntryTypeChange(0)"><span class="me-1">All</span><span
class="text-secondary">({{entries.length}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(1)"><span class="me-1">Movies</span><span
class="text-secondary">({{moviesCount()}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(2)"><span class="me-1">Tv-Series</span><span
class="text-secondary">({{seriesCount()}})</span></a>
</div>
</div>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class="pagination pagination-sm">
@@ -54,8 +42,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 -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { Entry } from '../../shared/models/entry.model';
import { LibraryService } from '../../core/services/library.service';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-watchlist',
@@ -18,7 +19,10 @@ export class WatchlistComponent {
currentPage: number = 1;
pageSize: number = 10;
constructor(private libraryService: LibraryService) {}
constructor(
private libraryService: LibraryService,
private toastr: ToastrService
) {}
ngOnInit() {
this.pageSize = this.getDefaultPageSize();
@@ -35,7 +39,11 @@ export class WatchlistComponent {
},
error: (error) => {
console.log(`Couldn't get entries.`, error);
// TODO show notification
this.toastr.success('Error', "Couldn't get watchlist items.", {
tapToDismiss: true,
progressBar: true,
progressAnimation: 'increasing',
});
},
});
}
@@ -53,15 +61,65 @@ export class WatchlistComponent {
temp = this.entries;
}
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
temp = await this.sortEntries(temp);
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.entriesToShow = temp.slice(startIndex, endIndex);
}
// ? pagination
sortEntries(entries: Entry[]) {
return entries.sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
);
}
// ! calculated fields
moviesCount() {
return this.entries.filter((e) => !e.is_tvseries).length;
}
seriesCount() {
return this.entries.filter((e) => e.is_tvseries).length;
}
hiddenCount() {
return this.entries.filter((e) => e.hidden).length;
}
// ! events
entryRemoved(event: Event) {
this.entries = this.entries.filter(
(e) => e.id.toString() != event.toString()
);
this.pageSize = this.getDefaultPageSize();
this.filterEntries();
}
onEntryTypeChange(entryType: number) {
this.entryType = entryType;
this.currentPage = 1;
this.filterEntries();
}
// ! pagination
setPageSize(event: any) {
this.pageSize = event.target.value;
this.filterEntries();
}
getDefaultPageSize() {
// TODO get default page size from settings service
return 54;
}
goToPage(page: number) {
this.currentPage = page;
this.filterEntries();
@@ -90,22 +148,4 @@ export class WatchlistComponent {
(_, i) => startPage + i
);
}
// ? end pagination
// ? setter
setEntryType(entryType: number) {
this.entryType = entryType;
this.currentPage = 1;
this.filterEntries();
}
setPageSize(event: any) {
this.pageSize = event.target.value;
this.filterEntries();
}
getDefaultPageSize() {
return 20;
}
}