From 5807652843257b605397e2639c744aba28c48060 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sat, 11 May 2024 05:33:30 +0100 Subject: [PATCH] add confirm delete for ep/entry seen + implemented actionsLock + fixed seasons order --- .../entry/entry-page/entry-page.component.css | 23 +- .../entry-page/entry-page.component.html | 41 ++- .../entry/entry-page/entry-page.component.ts | 244 +++++++++++------- 3 files changed, 189 insertions(+), 119 deletions(-) diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.css b/frontend/src/app/features/entry/entry-page/entry-page.component.css index c5b6499..47be8ba 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.css +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.css @@ -3,8 +3,7 @@ top: 0; left: 0; width: 100%; - height: 80vh; - /* Use 100vh to ensure it covers the viewport height */ + height: 100vh; z-index: -1; overflow: hidden; } @@ -35,13 +34,9 @@ background: linear-gradient(to bottom, rgba(255, 255, 255, 0.461) 10%, #eff1f3 100%); backdrop-filter: blur(10px); - /* Blur effect */ padding: 20px; - /* Padding for content */ border-radius: 8px; - /* Rounded corners */ border: 1px solid #eff1f3; - /* Optional: subtle border */ /* box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); */ } @@ -56,11 +51,7 @@ 37, 41, 0.7); - /* Dark semi-transparent background */ border: 1px solid #181c1f; - /* Subtle light border for contrast */ - /* box-shadow: 0 4px 6px rgba(255, 255, 255, 0.1); */ - /* Lighter shadow for a glow effect */ } .main-container { @@ -74,6 +65,7 @@ .poster { padding: px 10px 0 10px; + cursor: pointer; } .poster img { @@ -110,9 +102,10 @@ .right-col .entry-actions span { color: black; + font-size: 2rem; } -[data-bs-theme=dark] .right-col .entry-actions span { +[data-bs-theme=dark] .right-col .entry-actions span { color: white; } @@ -162,4 +155,12 @@ .right-col .entry-actions .favorite span { color: var(--shz-gold-1); +} + +.faved { + font-variation-settings: + 'FILL' 1, + 'wght' 400, + 'GRAD' 0, + 'opsz' 24 } \ No newline at end of file diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.html b/frontend/src/app/features/entry/entry-page/entry-page.component.html index 1369f35..046b800 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.html +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.html @@ -6,7 +6,7 @@
- Movie Poster + Movie Poster
    -
  • Rating: {{tmdbRating}}/10
  • +
  • TMDB Rating: + {{entry.entryRating.tmdb_rating | floatFormat:1}}/10
  • +
  • IMDB Rating: + {{entry.entryRating.imdb_rating | floatFormat:1}}/10
  • +
  • Rotten Romatoes: + {{entry.entryRating.rotten_tomatoes_rating | floatFormat:1}}/10
  • Premiere: {{this.entry.release_date | dateFormat:'MMM dd, yyyy'}}
  • Next Episode: {{nextEpisode}}
  • Status: {{status}}
  • Genre: {{genres}}
  • +
  • First Seen: {{entry.date_first_seen | + dateFormat:'MMM dd, yyyy'}} +
  • +
  • Last Seen: {{entry.date_last_seen | + dateFormat:'MMM dd, yyyy'}} +

@@ -72,13 +83,19 @@
+ + @@ -100,6 +117,7 @@

{{this.entry.release_date | dateFormat:'yyyy'}} • {{genres}}

+

{{this.entry.original_title}}

{{this.entry.tagline}}

{{this.entry.storyline}}

@@ -124,13 +142,13 @@
-
+ -
+

Watch History

@@ -181,11 +199,6 @@
-
diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.ts b/frontend/src/app/features/entry/entry-page/entry-page.component.ts index 1c552fb..24df3b8 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.ts +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.ts @@ -7,16 +7,17 @@ import { MatDialog } from '@angular/material/dialog'; import { Entry } from '../../../shared/models/entry.model'; import { EpisodeSeenDto } from '../../../shared/models/dtos/episode-seen.dto'; -import { DatePipe } from '@angular/common'; - import { UserCollectionsModalComponent } from '../../../shared/components/modals/list-selection-modal/user-collections-modal.component'; import { SeenModalComponent } from '../../../shared/components/modals/seen-modal/seen-modal.component'; +import { ConfirmModalComponent } from '../../../shared/components/modals/confirm-modal/confirm-modal.component'; import { EntrySeenService } from '../../../core/services/entry-seen.service'; import { EntryRatingsService } from '../../../core/services/entry-ratings.service'; import { EntryService } from '../../../core/services/entry.service'; import { EpisodeSeenService } from '../../../core/services/episode-seen.service'; import { SeasonService } from '../../../core/services/season.service'; +import { LibraryService } from '../../../core/services/library.service'; +import { ToastrService } from 'ngx-toastr'; @Component({ selector: 'app-entry-page', @@ -42,6 +43,8 @@ export class EntryPageComponent implements OnInit { public showAll = false; public initialCount = 2; + lockActions: boolean = false; + seenHistory: any[] = []; seenHistoryToShow: any[] = []; @@ -51,15 +54,16 @@ export class EntryPageComponent implements OnInit { pageSize: number = 10; constructor( - private route: ActivatedRoute, - private router: Router, - public dialog: MatDialog, private episodeSeenService: EpisodeSeenService, private entryService: EntryService, private seasonService: SeasonService, private entrySeenService: EntrySeenService, private entryRatingsService: EntryRatingsService, - private datePipe: DatePipe + private libraryService: LibraryService, + private dialog: MatDialog, + private route: ActivatedRoute, + private router: Router, + private toastr: ToastrService ) {} ngOnInit(): void { @@ -69,22 +73,33 @@ export class EntryPageComponent implements OnInit { if (this.entry.is_tvseries) { // ? sorting seasons - this.entry.seasons = this.entry.seasons.sort((a, b) => - a.name.localeCompare(b.name) - ); + this.entry.seasons = this.entry.seasons.sort((a, b) => { + if (b.season_number == 0) b.season_number = 30; // this will make the special season go last + if (a.season_number == 0) a.season_number = 30; // this will make the special season go last + + return a.season_number - b.season_number; + }); // ? getting seaons episodes this.entry.seasons.forEach((season) => { this.seasonService.getSeasonEpisodes(season.id).subscribe({ next: (episodes) => { - console.log( - `Loaded Season ${season.season_number} Episodes (${episodes.length})` - ); + // console.log( + // `Loaded Season ${season.season_number} Episodes (${episodes.length})` + // ); season.episodes = episodes; }, error: (error) => { console.log(`Couldn't fetch season episodes data:`, error); - // TODO show notification + this.toastr.success( + 'Error', + `Couldn't get season ${season.season_number} episodes.`, + { + tapToDismiss: true, + progressBar: true, + progressAnimation: 'increasing', + } + ); season.episodes = []; }, }); @@ -115,11 +130,9 @@ export class EntryPageComponent implements OnInit { width: '360px', }); - console.log('Seen dialog opened'); - dialogRef.afterClosed().subscribe((result) => { if (result) { - console.log('Seen dialog closed with:', result); + // console.log('Seen dialog closed with:', result); if (result.watchDate == '') { // TODO show no was passed date notification @@ -135,8 +148,12 @@ export class EntryPageComponent implements OnInit { next: (entrySeen) => { if (entrySeen) { // TODO show confirm notification - console.log(`EntrySeen Added`, entrySeen); + // console.log(`EntrySeen Added`, entrySeen); this.entry.entrySeen.push(entrySeen); + + if (this.entry.watchlist) { + this.libraryService.refrechEntries().subscribe(); + } } }, error: (error) => { @@ -169,31 +186,72 @@ export class EntryPageComponent implements OnInit { } removeEntrySeen(id: number) { - // TODO add confirm modal - this.entrySeenService.removeEntrySeen(id).subscribe({ - next: () => { - this.entry.entrySeen = this.entry.entrySeen.filter( - (item) => item.id !== id - ); - }, - error: (error) => { - // TODO show notification - console.error('Error deleting entrySeen:', error); + const dialogRef = this.dialog.open(ConfirmModalComponent, { + width: '400px', + data: { + title: 'Confirmation', + message: `Are you sure you want to delete this?`, + type: 'danger', }, }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + if (result.confirmed != true) return; + + this.entrySeenService.removeEntrySeen(id).subscribe({ + next: () => { + this.toastr.success('success', `Removed successfuly.`, { + tapToDismiss: true, + progressBar: true, + progressAnimation: 'increasing', + }); + this.entry.entrySeen = this.entry.entrySeen.filter( + (item) => item.id !== id + ); + }, + error: (error) => { + // TODO show notification + console.error('Error deleting entrySeen:', error); + }, + }); + } + }); } toggleFavorite() { + this.lockActions = true; this.entry.favorit = !this.entry.favorit; this.entryService.updateEntry(this.entry).subscribe({ next: (entry) => { - console.log(`Entry updated: `, entry); + // console.log(`Entry updated: `, entry); this.entry = entry; }, error: (error) => { console.log(`Error updating entry: `, error); this.entry.favorit = !this.entry.favorit; }, + complete: () => { + this.lockActions = false; + }, + }); + } + + toggleHidden() { + this.lockActions = true; + this.entry.hidden = !this.entry.hidden; + this.entryService.updateEntry(this.entry).subscribe({ + next: (entry) => { + // console.log(`Entry updated: `, entry); + this.entry = entry; + }, + error: (error) => { + console.log(`Error updating entry: `, error); + this.entry.favorit = !this.entry.favorit; + }, + complete: () => { + this.lockActions = false; + } }); } @@ -214,16 +272,20 @@ export class EntryPageComponent implements OnInit { } refrechEntry() { + this.lockActions = true; this.entryService.refrechEntryById(this.entry.id).subscribe({ next: (entry) => { this.entry = entry; - console.log(`Entry refreched: `, entry); + // console.log(`Entry refreched: `, entry); // TODO show updated notification }, error: (error) => { // TODO show error notification console.error('Error refreching movie info:', error); }, + complete: () => { + this.lockActions = false; + }, }); } @@ -263,13 +325,13 @@ export class EntryPageComponent implements OnInit { }); this.seenHistory = episodeSeens; - console.log(`Episode Seen History Received: `, episodeSeens); + // console.log(`Episode Seen History Received: `, episodeSeens); this.filterEpisodesSeenHistory(); }, error: (error) => { this.seenHistory = [] as EpisodeSeenDto[]; this.filterEpisodesSeenHistory(); - console.log(error); + console.log(`Error getting episodes watch history`, error); }, }); } @@ -301,12 +363,9 @@ export class EntryPageComponent implements OnInit { dialogRef.afterClosed().subscribe((result) => { // ? dialog closed - if (result == null) { - return console.log('Seen dialog was cancelled'); - } - + if (result == null) return; // ? dialog confimed - console.log('Episode seen dialog closed with:', result); + // console.log('Episode seen dialog closed with:', result); if (result.watchDate == '') { // TODO show no date was passed notification return console.log(`Episode seen dialog closed with no date.`); @@ -317,7 +376,7 @@ export class EntryPageComponent implements OnInit { this.episodeSeenService.updateEpisodeSeen(episodeSeen).subscribe({ next: () => { - console.log(`Episode seen updated.`); + // console.log(`Episode seen updated.`); this.getEpisodesSeenHistory(); // TODO show notification }, @@ -332,39 +391,56 @@ export class EntryPageComponent implements OnInit { deleteEpisodeSeen(episodeSeen: EpisodeSeenDto) { if (episodeSeen.id == null) return; - // first start by calling the service and deleting the episode-seen - this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({ - next: () => { - console.log(`Episode seen deleted.`); - // call this function to fetch the new episode-seen history - this.getEpisodesSeenHistory(); - - // trying to update the episodes seen progress bar in the season card - // by fetching a new updated episodes list - this.entry.seasons.forEach(async (season) => { - if (season.season_number == episodeSeen.season_number) { - this.seasonService.getSeasonEpisodes(season.id).subscribe({ - next: (episodes) => { - console.log( - `Loaded Season ${season.season_number} Episodes (${episodes.length})` - ); - season.episodes = episodes; - }, - error: (error) => { - console.log(`Couldn't fetch season episodes data:`, error); - // TODO show notification - season.episodes = []; - }, - }); - } - }); - // TODO show notification - }, - error: (error) => { - console.log(`Episode seen delete error: `, error); + const dialogRef = this.dialog.open(ConfirmModalComponent, { + width: '400px', + data: { + title: 'Confirmation', + message: `Are you sure you want to delete this?`, + type: 'danger', }, }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + console.log(result); + if (result.confirmed != true) return; + + // first start by calling the service and deleting the episode-seen + this.episodeSeenService.removeEpisodeSeen(episodeSeen.id).subscribe({ + next: () => { + // console.log(`Episode seen deleted.`); + // call this function to fetch the new episode-seen history + this.getEpisodesSeenHistory(); + + // trying to update the episodes seen progress bar in the season card + // by fetching a new updated episodes list + this.entry.seasons.forEach(async (season) => { + if (season.season_number == episodeSeen.season_number) { + this.seasonService.getSeasonEpisodes(season.id).subscribe({ + next: (episodes) => { + // console.log( + // `Loaded Season ${season.season_number} Episodes (${episodes.length})` + // ); + season.episodes = episodes; + }, + error: (error) => { + console.log(`Couldn't fetch season episodes data:`, error); + // TODO show notification + season.episodes = []; + }, + }); + } + }); + // TODO show notification + }, + error: (error) => { + console.log(`Episode seen delete error: `, error); + }, + }); + } + }); } + triggerEpisodeWatchedDeletedEvent() { console.log(`Emitted Episode Watched Deleted Event`); } @@ -406,23 +482,18 @@ export class EntryPageComponent implements OnInit { this.showAll = !this.showAll; } + enlargePoster() { + window.open( + 'https://image.tmdb.org/t/p/original' + this.entry.poster_path, + '_blank' + ); + } + // * getters get status() { return this.entry.status; } - get createdDate() { - return this.datePipe.transform(this.entry.createdAt, 'dd MMMM, yyyy'); - } - - get releaseDate() { - return this.datePipe.transform(this.entry.release_date, 'MMM dd, yyyy'); - } - - get year() { - return this.datePipe.transform(this.entry.release_date, 'yyyy'); - } - get runtime() { return this.entry.runtime; } @@ -431,21 +502,6 @@ export class EntryPageComponent implements OnInit { return this.entry.genres.join(', '); } - get userRating(): string { - if (!this.entry.entryRating.user_rating) return '0'; - return this.entry.entryRating.user_rating.toFixed(1); - } - - get tmdbRating(): string { - if (!this.entry.entryRating.tmdb_rating) return '0'; - return this.entry.entryRating.tmdb_rating.toFixed(1); - } - - get imdbRating(): string { - if (!this.entry.entryRating.imdb_rating) return '0'; - return this.entry.entryRating.imdb_rating.toFixed(1); - } - get poster(): string { if (this.entry.poster_path == null) return 'assets/images/default/default-poster.png';