changes to season main card

This commit is contained in:
X4Lo committed 2024-04-20 15:47:47 +01:00
1 parent 5b1b02cf61
commit 252d7093b2
5 files changed
+113 -18

No files matched your search

+10
View File
@@ -10,6 +10,10 @@ import { SidebarComponent } from './components/sidebar/sidebar.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { RouterModule } from '@angular/router';
import { EntrySeenService } from './services/entry-seen.service';
import { EpisodeService } from './services/episode.service';
import { EpisodeSeenService } from './services/episode-seen.service';
import { ThemeService } from './services/theme.service';
import { SeasonService } from './services/season.service';
@NgModule({
declarations: [SidebarComponent, NavbarComponent],
@@ -21,6 +25,12 @@ import { EntrySeenService } from './services/entry-seen.service';
EntrySeenService,
UserCollectionService,
ToggleService,
EpisodeService,
EpisodeSeenService,
SeasonService,
ToggleService,
ThemeService,
],
exports: [SidebarComponent, NavbarComponent],
})
@@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root',
})
export class EpisodeService {
private backend_apiUrl = 'http://localhost:4000/api/v1';
private apiAction = 'episodes';
constructor(private http: HttpClient) {}
}
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Season } from '../../shared/models/season.model';
import { Episode } from '../../shared/models/episode.models';
@Injectable({
providedIn: 'root',
@@ -24,4 +25,10 @@ export class SeasonService {
[null]
);
}
getSeasonEpisodes(id: number) {
return this.http.get<Episode[]>(
`${this.backend_apiUrl}/${this.apiAction}/${id}/episodes`
);
}
}
@@ -6,13 +6,17 @@
<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">
<div class="d-flex align-items-center justify-content-between mb-4 mt-3">
<div class="progress" style="height: 7px; width: 90%;"> <!-- Adjust width as needed -->
<div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="episodesWatchedCount" aria-valuemin="0" [attr.aria-valuemax]="season.episode_count"></div>
<div class="progress-bar" role="progressbar" [style]="'width:'+ episodesWatchedPercentage + '%'"
[attr.aria-valuenow]="episodesWatchedPercentage" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" style="height: 20px; width: 20px;">
<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">
<input class="form-check-input" type="checkbox" style="height: 20px; width: 20px;" [checked]="isChecked"
(change)="handleCheckChange()">
</div>
</div>
<!-- <p class="mb-0 overview">{{season.overview}}</p> -->
@@ -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;
// });
}
}
}