From 2a43e9108eee9bb51c122c2e76aa52390bf63b91 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Sat, 12 Apr 2025 21:05:14 +0100 Subject: [PATCH] F: Fixed tvseries entry not showing up correctly in library page when adding a seen date to it while it is in watchlist. --- .../entry/entry-page/entry-page.component.ts | 73 +++++++++++++++---- .../episode-seen-modal.component.ts | 6 ++ 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.ts b/frontend/src/app/features/entry/entry-page/entry-page.component.ts index f70a9bf..712f420 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.ts +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.ts @@ -232,7 +232,6 @@ export class EntryPageComponent implements OnInit { // ? if the entry was in watch list creating and entry-seen would have removed it // ? from the watchlist, so now we need to refrech libraryService in order to // ? update the watchlist page - this.entry.isInLibrary = true; this.entry.watchlist = false; // ? update enrty last_seen & first_seen dates @@ -488,7 +487,7 @@ export class EntryPageComponent implements OnInit { // mapping data.forEach((item) => { - let e = { + const episodeSeenCreateDto = { id: item.id, entryId: item.entry_id, @@ -504,7 +503,7 @@ export class EntryPageComponent implements OnInit { updatedAt: item.updatedAt, } as EpisodeSeenCreateDto; - episodeSeens.push(e); + episodeSeens.push(episodeSeenCreateDto); }); this.seenHistory = episodeSeens; @@ -534,9 +533,7 @@ export class EntryPageComponent implements OnInit { } addEpisodeSeen() { - if (!this.entry) return; - - this.seenHistory[0]; + if (!this.entry || !this.entry.is_tvseries) return; const dialogRef = this.dialog.open(EpisodeSeenModalComponent, { width: '360px', @@ -550,9 +547,27 @@ export class EntryPageComponent implements OnInit { dialogRef.afterClosed().subscribe((result) => { // ? if an episode-seen was created then refresh the watch history table if (result && result.created) { + // TODO: improve this logic, there shouldn't be a need to whole recall // ? call this function to fetch the new episode-seen history this.getEpisodesSeenHistory(); + this.entry.watchlist = false; + + // ? update enrty last_seen & first_seen dates + if ( + !this.entry.date_last_seen || + this.entry.date_last_seen < result.episodeSeen.date_seen + ) { + this.entry.date_last_seen = result.episodeSeen.date_seen; + } + + if ( + !this.entry.date_first_seen || + this.entry.date_first_seen > result.episodeSeen.date_seen + ) { + this.entry.date_first_seen = result.episodeSeen.date_seen; + } + // ? Updating the episodes seen progress bar in the season card // ? by fetching a new updated episodes list this.entry.seasons.forEach(async (season) => { @@ -572,6 +587,8 @@ export class EntryPageComponent implements OnInit { }); } }); + + this.libraryService.updateEntry(this.entry); } }); } @@ -588,11 +605,29 @@ export class EntryPageComponent implements OnInit { }); dialogRef.afterClosed().subscribe((result) => { - if (result == null) return; - if (!result.updated) return; + if (result && result.updated) { + // ? call this function to fetch the new episode-seen history + this.getEpisodesSeenHistory(); - // ? call this function to fetch the new episode-seen history - this.getEpisodesSeenHistory(); + this.entry.watchlist = false; + + // ? update enrty last_seen & first_seen dates + if ( + !this.entry.date_last_seen || + this.entry.date_last_seen < result.episodeSeen.date_seen + ) { + this.entry.date_last_seen = result.episodeSeen.date_seen; + } + + if ( + !this.entry.date_first_seen || + this.entry.date_first_seen > result.episodeSeen.date_seen + ) { + this.entry.date_first_seen = result.episodeSeen.date_seen; + } + + this.libraryService.updateEntry(this.entry); + } }); } @@ -609,20 +644,26 @@ export class EntryPageComponent implements OnInit { }); dialogRef.afterClosed().subscribe((result) => { - if (result) { - if (result.confirmed != true) return; - + if (result && result.confirmed) { // first start by calling the service and deleting the episode-seen this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({ next: () => { // console.log(`Episode seen deleted.`); - // ? call this function to fetch the new episode-seen history - // this.getEpisodesSeenHistory(); this.seenHistory = this.seenHistory.filter( (eps) => eps.id != episodeSeen.id ); this.filterEpisodesSeenHistory(); + // ? update enrty last_seen & first_seen dates + if (this.seenHistory.length == 0) { + this.entry.date_last_seen = null; + this.entry.date_first_seen = null; + } else { + this.entry.date_last_seen = this.seenHistory[0].date_seen; + this.entry.date_first_seen = + this.seenHistory[this.seenHistory.length - 1].date_seen; + } + // ? Updating the episodes seen progress bar in the season card // ? by fetching a new updated episodes list this.entry.seasons.forEach(async (season) => { @@ -642,6 +683,8 @@ export class EntryPageComponent implements OnInit { }); } }); + + this.libraryService.updateEntry(this.entry); // TODO show notification }, error: (error) => { diff --git a/frontend/src/app/shared/components/modals/episode-seen-modal/episode-seen-modal.component.ts b/frontend/src/app/shared/components/modals/episode-seen-modal/episode-seen-modal.component.ts index bae4ded..d374e43 100644 --- a/frontend/src/app/shared/components/modals/episode-seen-modal/episode-seen-modal.component.ts +++ b/frontend/src/app/shared/components/modals/episode-seen-modal/episode-seen-modal.component.ts @@ -155,6 +155,11 @@ export class EpisodeSeenModalComponent { if (episodeSeen) { return this.dialogRef.close({ updated: true, + episodeSeen: { + ...this.episodeSeen, + date_seen: episodeSeen.date_seen, + seen_with: episodeSeen.seen_with, + }, }); } }, @@ -177,6 +182,7 @@ export class EpisodeSeenModalComponent { if (episodeSeen) { return this.dialogRef.close({ created: true, + episodeSeen: episodeSeen, // ? returning the season number so it can be used to refrech the- // ? season card progress bar in the entry page season_number: this.selectedSeason?.season_number,