add confirmModal + float format pipe + moved a component

This commit is contained in:
X4Lo committed 2024-05-10 09:39:13 +01:00
1 parent 49f8cd601b
commit 1361fc7b18
12 files changed
+112 -31

No files matched your search

@@ -0,0 +1,37 @@
.list-item-1 {
padding-top: 1px;
}
.list-title {
font-size: 20px;
}
.list-line {
max-height: 105px;
border-radius: 1px;
overflow: hidden;
padding: 2px;
box-sizing: border-box;
}
.overview {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
max-height: 50px;
}
.list-line:hover {
background-color: var(--shz-light-bgh);
}
:host-context([data-bs-theme="dark"]) .list-line:hover {
background-color: var(--shz-dark-bgh);
}
.progress {
flex-grow: 1; /* Makes the progress bar expand to fill available space */
margin-right: 10px; /* Adds some space between the progress bar and the checkbox */
}
@@ -0,0 +1,22 @@
<div class="d-flex align-items-start gap-2 list-line" @fadeInOut>
<img [src]="posterPath" width="70" height="105" class="" alt="Episode poster">
<div class="flex-grow-1 list-item-1">
<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" 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>
</div>
<div style="margin-right: 5px; min-width: 35px;">
{{episodesWatchedCount}}/{{this.season.episode_count}}
</div>
<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>
</div>
</div>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SeasonMainCardComponent } from './season-main-card.component';
describe('SeasonMainCardComponent', () => {
let component: SeasonMainCardComponent;
let fixture: ComponentFixture<SeasonMainCardComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SeasonMainCardComponent]
})
.compileComponents();
fixture = TestBed.createComponent(SeasonMainCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,176 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Season } from '../../../shared/models/season.model';
import { SeasonService } from '../../../core/services/season.service';
import {
trigger,
state,
style,
transition,
animate,
} from '@angular/animations';
import { Episode } from '../../../shared/models/episode.models';
import { EpisodeSeenService } from '../../../core/services/episode-seen.service';
import { MatDialog } from '@angular/material/dialog';
import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component';
@Component({
selector: 'app-season-main-card',
templateUrl: './season-main-card.component.html',
styleUrl: './season-main-card.component.css',
animations: [
trigger('fadeInOut', [
transition(':enter', [
// void => *
style({ opacity: 0 }),
animate('0.5s ease-in', style({ opacity: 1 })),
]),
transition(':leave', [
// * => void
animate('0.5s ease-out', style({ opacity: 0 })),
]),
]),
],
})
export class SeasonMainCardComponent implements OnInit {
@Output() episodeWatchedEvent = new EventEmitter();
@Input() season: Season = {} as Season;
isChecked: boolean = false;
isLocked: boolean = false;
constructor(
private seasonService: SeasonService,
private episodeSeenService: EpisodeSeenService,
public dialog: MatDialog
) {}
ngOnInit(): void {
this.seasonService.getSeasonEpisodes(this.season.id).subscribe({
next: (episodes) => {
console.log(`Loaded Season Episodes: `, episodes);
this.season.episodes = episodes;
},
error: (error) => {
console.log(`Couldn't fetch season episodes data:`, error);
// TODO show notification
},
});
}
get posterPath() {
if (this.season.poster_path == null)
return 'assets/images/default/default-poster.png';
return 'http://image.tmdb.org/t/p/w154/' + this.season.poster_path;
}
get episodesWatchedPercentage() {
let count = 0;
if (!this.season.episodes) return 0;
this.season.episodes.forEach((ep) => {
if (ep.date_first_seen != null) count++;
});
if (this.season.episode_count == null) return 0;
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;
}
async episodeMarkSeenClick() {
if (this.isLocked) return;
this.isLocked = true;
let selectedEpisode = {} as Episode;
let selectedEpisodeIndex = -1;
// * starts looping from the last available episode
if (
this.season.episodes[this.season.episodes.length - 1].date_first_seen ==
null
) {
// ? untils it finds that the previous episode episode is marked as seen
// ? > in that case it chooses the current one to mark
for (let i = this.season.episodes.length - 1; i >= 0; i--) {
if (i == 0 || this.season.episodes[i - 1].date_first_seen != null) {
selectedEpisodeIndex = i;
selectedEpisode = this.season.episodes[i];
break;
}
}
} else {
// ? in case the last episode is already marked as seen but
// ? there are other before it that are not, then start from
// ? episode 1 and look for any that are not seen
for (let i = 0; i < this.season.episodes.length; i++) {
if (this.season.episodes[i].date_first_seen == null) {
selectedEpisodeIndex = i;
selectedEpisode = this.season.episodes[i];
break;
}
}
}
// + end loocking for episode
if (selectedEpisode == null) return;
if (selectedEpisode.date_first_seen != null) return;
// ? show the episode seen modal
const dialogRef = this.dialog.open(SeenModalComponent, {
width: '400px',
});
console.log('Episode seen dialog opened');
await dialogRef.afterClosed().subscribe((result) => {
if (result) {
console.log('Episode seen dialog closed with:', result);
if (result.watchDate == '') {
// TODO show no date was passed notification
this.isLocked = false;
return;
}
let watchDate = result.watchDate;
let watchedWith = result.watchedWith.split('\n').join(', ');
this.episodeSeenService
.createEpisodeSeen(
this.season.entry_id,
selectedEpisode.id,
watchDate,
watchedWith
)
.subscribe({
next: (episodeSeen) => {
console.log(`Episode marked as seen`, episodeSeen);
// TODO get actualy date_first_seen & date_last_seen for episode seen (not just place holders)
this.season.episodes[selectedEpisodeIndex].date_first_seen =
new Date();
this.season.episodes[selectedEpisodeIndex].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;
},
});
} else {
console.log('Seen dialog was cancelled');
this.isLocked = false;
}
});
}
}