F: Fixed tvseries entry not showing up correctly in library page when adding a seen date to it while it is in watchlist.

This commit is contained in:
X4Lo committed 2025-04-12 21:05:14 +01:00
1 parent 6a102f86e8
commit 2a43e9108e
2 files changed
+64 -15

No files matched your search

@@ -232,7 +232,6 @@ export class EntryPageComponent implements OnInit {
// ? if the entry was in watch list creating and entry-seen would have removed it // ? 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 // ? from the watchlist, so now we need to refrech libraryService in order to
// ? update the watchlist page // ? update the watchlist page
this.entry.isInLibrary = true;
this.entry.watchlist = false; this.entry.watchlist = false;
// ? update enrty last_seen & first_seen dates // ? update enrty last_seen & first_seen dates
@@ -488,7 +487,7 @@ export class EntryPageComponent implements OnInit {
// mapping // mapping
data.forEach((item) => { data.forEach((item) => {
let e = { const episodeSeenCreateDto = {
id: item.id, id: item.id,
entryId: item.entry_id, entryId: item.entry_id,
@@ -504,7 +503,7 @@ export class EntryPageComponent implements OnInit {
updatedAt: item.updatedAt, updatedAt: item.updatedAt,
} as EpisodeSeenCreateDto; } as EpisodeSeenCreateDto;
episodeSeens.push(e); episodeSeens.push(episodeSeenCreateDto);
}); });
this.seenHistory = episodeSeens; this.seenHistory = episodeSeens;
@@ -534,9 +533,7 @@ export class EntryPageComponent implements OnInit {
} }
addEpisodeSeen() { addEpisodeSeen() {
if (!this.entry) return; if (!this.entry || !this.entry.is_tvseries) return;
this.seenHistory[0];
const dialogRef = this.dialog.open(EpisodeSeenModalComponent, { const dialogRef = this.dialog.open(EpisodeSeenModalComponent, {
width: '360px', width: '360px',
@@ -550,9 +547,27 @@ export class EntryPageComponent implements OnInit {
dialogRef.afterClosed().subscribe((result) => { dialogRef.afterClosed().subscribe((result) => {
// ? if an episode-seen was created then refresh the watch history table // ? if an episode-seen was created then refresh the watch history table
if (result && result.created) { 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 // ? call this function to fetch the new episode-seen history
this.getEpisodesSeenHistory(); 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 // ? Updating the episodes seen progress bar in the season card
// ? by fetching a new updated episodes list // ? by fetching a new updated episodes list
this.entry.seasons.forEach(async (season) => { 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) => { dialogRef.afterClosed().subscribe((result) => {
if (result == null) return; if (result && result.updated) {
if (!result.updated) return; // ? call this function to fetch the new episode-seen history
this.getEpisodesSeenHistory();
// ? call this function to fetch the new episode-seen history this.entry.watchlist = false;
this.getEpisodesSeenHistory();
// ? 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) => { dialogRef.afterClosed().subscribe((result) => {
if (result) { if (result && result.confirmed) {
if (result.confirmed != true) return;
// first start by calling the service and deleting the episode-seen // first start by calling the service and deleting the episode-seen
this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({ this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({
next: () => { next: () => {
// console.log(`Episode seen deleted.`); // console.log(`Episode seen deleted.`);
// ? call this function to fetch the new episode-seen history
// this.getEpisodesSeenHistory();
this.seenHistory = this.seenHistory.filter( this.seenHistory = this.seenHistory.filter(
(eps) => eps.id != episodeSeen.id (eps) => eps.id != episodeSeen.id
); );
this.filterEpisodesSeenHistory(); 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 // ? Updating the episodes seen progress bar in the season card
// ? by fetching a new updated episodes list // ? by fetching a new updated episodes list
this.entry.seasons.forEach(async (season) => { this.entry.seasons.forEach(async (season) => {
@@ -642,6 +683,8 @@ export class EntryPageComponent implements OnInit {
}); });
} }
}); });
this.libraryService.updateEntry(this.entry);
// TODO show notification // TODO show notification
}, },
error: (error) => { error: (error) => {
@@ -155,6 +155,11 @@ export class EpisodeSeenModalComponent {
if (episodeSeen) { if (episodeSeen) {
return this.dialogRef.close({ return this.dialogRef.close({
updated: true, updated: true,
episodeSeen: {
...this.episodeSeen,
date_seen: episodeSeen.date_seen,
seen_with: episodeSeen.seen_with,
},
}); });
} }
}, },
@@ -177,6 +182,7 @@ export class EpisodeSeenModalComponent {
if (episodeSeen) { if (episodeSeen) {
return this.dialogRef.close({ return this.dialogRef.close({
created: true, created: true,
episodeSeen: episodeSeen,
// ? returning the season number so it can be used to refrech the- // ? returning the season number so it can be used to refrech the-
// ? season card progress bar in the entry page // ? season card progress bar in the entry page
season_number: this.selectedSeason?.season_number, season_number: this.selectedSeason?.season_number,