add episode seen history in entry page
This commit is contained in:
1 parent
cf305cabae
commit
dbeb0ee524
11 files changed
+288
-64
No files matched your search
@@ -6,7 +6,7 @@
|
||||
<h6 class="mb-0 list-title">{{season.name}}</h6>
|
||||
<p class="mb-0">{{season.air_date | dateFormat:'yyyy'}}</p>
|
||||
|
||||
<div class="d-flex align-items-center justify-content-between mb-4 mt-3">
|
||||
<div class="d-flex align-items-center justify-content-between mb-4 mt-3" style="height: 40px;">
|
||||
<div class="progress" style="height: 7px; width: 90%;"> <!-- Adjust width as needed -->
|
||||
<div class="progress-bar" role="progressbar" [style]="'width:'+ episodesWatchedPercentage + '%'"
|
||||
[attr.aria-valuenow]="episodesWatchedPercentage" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
@@ -14,10 +14,15 @@
|
||||
<div style="margin-right: 5px;">
|
||||
{{episodesWatchedCount}}/{{this.season.episode_count}}
|
||||
</div>
|
||||
<div class="form-check" style="margin-right: 5px;" *ngIf="episodesWatchedCount < this.season.episode_count">
|
||||
<button *ngIf="episodesWatchedCount < this.season.episode_count" type="button"
|
||||
class="btn btn-outline-primary rounded-pill d-flex justify-content-center align-items-center"
|
||||
style="height: 30px; width: 40px; margin-right: 5px;" (click)="episodeMarkSeenClick()">
|
||||
<span class="material-symbols-outlined">check</span>
|
||||
</button>
|
||||
<!-- <div class="form-check" style="margin-right: 5px;" *ngIf="episodesWatchedCount < this.season.episode_count">
|
||||
<input class="form-check-input" type="checkbox" style="height: 20px; width: 20px;" [checked]="isChecked"
|
||||
(change)="handleCheckChange()">
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
<!-- <p class="mb-0 overview">{{season.overview}}</p> -->
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface EpisodeSeenDto {
|
||||
id: number;
|
||||
|
||||
entryId: number;
|
||||
episodeId: number;
|
||||
|
||||
season_number: number;
|
||||
episode_number: number;
|
||||
|
||||
date_seen: Date;
|
||||
seen_with: string;
|
||||
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
export interface EpisodeSeen {
|
||||
id: number;
|
||||
|
||||
entry_id: number;
|
||||
episode_id: number;
|
||||
|
||||
date_seen: Date;
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface Season {
|
||||
tmdb_id: string;
|
||||
imdb_id: string;
|
||||
|
||||
entry_id: string;
|
||||
entry_id: number;
|
||||
|
||||
name: string;
|
||||
overview: string;
|
||||
|
||||
Reference in new issue
Block a user