changes to season main card
This commit is contained in:
1 parent
5b1b02cf61
commit
252d7093b2
5 files changed
+113
-18
No files matched your search
@@ -8,6 +8,8 @@ import {
|
||||
transition,
|
||||
animate,
|
||||
} from '@angular/animations';
|
||||
import { Episode } from '../../models/episode.models';
|
||||
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-season-main-card',
|
||||
@@ -29,21 +31,26 @@ import {
|
||||
})
|
||||
export class SeasonMainCardComponent implements OnInit {
|
||||
@Input() season: Season = {} as Season;
|
||||
isChecked: boolean = false;
|
||||
isLocked: boolean = false;
|
||||
|
||||
constructor(private seasonService: SeasonService) {}
|
||||
constructor(
|
||||
private seasonService: SeasonService,
|
||||
private episodeSeenService: EpisodeSeenService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
// // TODO: GET SEASON EPISODES
|
||||
// this.seasonService.getSeasonById(this.season.id).subscribe({
|
||||
// next: (season) => {
|
||||
// console.log(season);
|
||||
// this.season = season;
|
||||
// },
|
||||
// error: (error) => {
|
||||
// console.log(`Couldn't fetch season data:`, error);
|
||||
// // TODO show notification
|
||||
// },
|
||||
// });
|
||||
// TODO: GET SEASON EPISODES
|
||||
this.seasonService.getSeasonEpisodes(this.season.id).subscribe({
|
||||
next: (episodes) => {
|
||||
console.log(episodes);
|
||||
this.season.episodes = episodes;
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(`Couldn't fetch season episodes data:`, error);
|
||||
// TODO show notification
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get posterPath() {
|
||||
@@ -53,8 +60,9 @@ export class SeasonMainCardComponent implements OnInit {
|
||||
return 'http://image.tmdb.org/t/p/w154/' + this.season.poster_path;
|
||||
}
|
||||
|
||||
get episodesWatchedCount() {
|
||||
get episodesWatchedPercentage() {
|
||||
let count = 0;
|
||||
if (!this.season.episodes) return 0;
|
||||
this.season.episodes.forEach((ep) => {
|
||||
if (ep.date_first_seen != null) count++;
|
||||
});
|
||||
@@ -64,4 +72,58 @@ export class SeasonMainCardComponent implements OnInit {
|
||||
let value = (count * 100) / this.season.episode_count;
|
||||
return value;
|
||||
}
|
||||
|
||||
get episodesWatchedCount() {
|
||||
let count = 0;
|
||||
if (!this.season.episodes) return 0;
|
||||
this.season.episodes.forEach((ep) => {
|
||||
if (ep.date_first_seen != null) count++;
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
handleCheckChange() {
|
||||
this.isChecked = true;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('checking');
|
||||
// this.executeFunction()
|
||||
// .then(() => {
|
||||
// this.isChecked = false;
|
||||
// console.log('unchecking');
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error('Failed to execute function:', error);
|
||||
// this.isChecked = false;
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user