diff --git a/frontend/src/app/features/watchlist/watchlist.component.html b/frontend/src/app/features/watchlist/watchlist.component.html index 7d3ceba..c02a055 100644 --- a/frontend/src/app/features/watchlist/watchlist.component.html +++ b/frontend/src/app/features/watchlist/watchlist.component.html @@ -1,6 +1,6 @@ +
+
+ All({{entries.length}}) + Movies({{moviesCount()}}) + Tv-Series({{seriesCount()}}) +
+
+
- - +
diff --git a/frontend/src/app/features/watchlist/watchlist.component.ts b/frontend/src/app/features/watchlist/watchlist.component.ts index 89951b0..af0149c 100644 --- a/frontend/src/app/features/watchlist/watchlist.component.ts +++ b/frontend/src/app/features/watchlist/watchlist.component.ts @@ -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; - } }