add episode seen history in entry page

This commit is contained in:
X4Lo committed 2024-04-22 17:41:30 +01:00
1 parent cf305cabae
commit dbeb0ee524
11 files changed
+288 -64

No files matched your search

@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Season } from '../../models/season.model';
import { SeasonService } from '../../../core/services/season.service';
import {
@@ -30,6 +30,7 @@ import { EpisodeSeenService } from '../../../core/services/episode-seen.service'
],
})
export class SeasonMainCardComponent implements OnInit {
@Output() episodeWatchedEvent = new EventEmitter();
@Input() season: Season = {} as Season;
isChecked: boolean = false;
isLocked: boolean = false;
@@ -43,7 +44,7 @@ export class SeasonMainCardComponent implements OnInit {
// TODO: GET SEASON EPISODES
this.seasonService.getSeasonEpisodes(this.season.id).subscribe({
next: (episodes) => {
console.log(episodes);
console.log(`Loaded Season Episodes: `, episodes);
this.season.episodes = episodes;
},
error: (error) => {
@@ -82,48 +83,42 @@ export class SeasonMainCardComponent implements OnInit {
return count;
}
handleCheckChange() {
this.isChecked = true;
episodeMarkSeenClick() {
if (this.isLocked) return;
this.isLocked = true;
if (this.isChecked) {
for (let i = this.season.episode_count; i > 0; i--) {
if (this.season.episodes[i - 1].date_first_seen != null) {
let currentEpisode = this.season.episodes[i];
this.episodeSeenService
.createEpisodeSeen(currentEpisode.id, new Date(), 'Me, My Self & I')
.subscribe({
next: (episodeSeen) => {
console.log(`Episode marked as seen`, episodeSeen);
this.season.episodes[i].date_first_seen = new Date();
this.season.episodes[i].date_last_seen = new Date();
// TODO show notification
this.isChecked = false;
this.isLocked = false;
},
error: (error) => {
console.log(`Couldn't mark episode as seen:`, error);
// TODO show notification
this.isChecked = false;
this.isLocked = false;
},
});
break;
}
// starts looping from the last available episode
for (let i = this.season.episode_count; i >= 0; i--) {
// ? untils it finds that the previous episode episode is marked as seen
// ? > in that case it chooses the current one to mark
if (i == 0 || this.season.episodes[i - 1].date_first_seen != null) {
let currentEpisode = this.season.episodes[i];
// todo: show episode seen modal
this.episodeSeenService
.createEpisodeSeen(
this.season.entry_id,
currentEpisode.id,
new Date(),
'Me, My Self & I'
)
.subscribe({
next: (episodeSeen) => {
console.log(`Episode marked as seen`, episodeSeen);
this.season.episodes[i].date_first_seen = new Date();
this.season.episodes[i].date_last_seen = new Date();
this.episodeWatchedEvent.emit();
// TODO show notification
},
error: (error) => {
console.log(`Couldn't mark episode as seen:`, error);
// TODO show notification
},
complete: () => {
this.isLocked = false;
},
});
break;
}
// console.log('checking');
// this.executeFunction()
// .then(() => {
// this.isChecked = false;
// console.log('unchecking');
// })
// .catch((error) => {
// console.error('Failed to execute function:', error);
// this.isChecked = false;
// });
}
}
}