From 85330760808e766c7a1a82910017dc778aa2d36e Mon Sep 17 00:00:00 2001 From: X4Lo Date: Sun, 13 Apr 2025 03:54:55 +0100 Subject: [PATCH] F: Added toast to entry-page and other components --- .../calendar-page/calendar-page.component.ts | 9 +- .../entry/entry-page/entry-page.component.ts | 153 +++++++++++------- .../entry-settings-modal.component.ts | 7 +- .../user-collections-modal.component.css | 1 - .../user-collections-modal.component.ts | 16 +- .../modals/seen-modal/seen-modal.component.ts | 12 +- 6 files changed, 114 insertions(+), 84 deletions(-) diff --git a/frontend/src/app/features/calendar/calendar-page/calendar-page.component.ts b/frontend/src/app/features/calendar/calendar-page/calendar-page.component.ts index 7c832aa..7632ec9 100644 --- a/frontend/src/app/features/calendar/calendar-page/calendar-page.component.ts +++ b/frontend/src/app/features/calendar/calendar-page/calendar-page.component.ts @@ -39,7 +39,7 @@ export class CalendarPageComponent implements OnInit { constructor( private episodeService: EpisodeService, - private toastService: ToastService, + private toast: ToastService, private entryService: EntryService, private router: Router, private configService: ConfigService @@ -56,13 +56,13 @@ export class CalendarPageComponent implements OnInit { // console.log('First Day of First Week:', firstDayOfFirstWeek); // console.log('Last Day of Last Week:', lastDayOfLastWeek); - this.toastService.show('Welcome', 'hello', 'success'); this.entryService.syncSeries().subscribe({ next: (result) => { - console.log(`Tv-Series Synced Successfully`); + // console.log(`Tv-Series Synced Successfully`); }, error: (error) => { - console.log(`Error Syncing Tv-Series Successfully`); + this.toast.show('', 'Error Syncing Tv-Series', 'error'); + // console.log(`Error Syncing Tv-Series`); }, }); // this.fetchEpisodes(firstDayOfFirstWeek, lastDayOfLastWeek); @@ -107,7 +107,6 @@ export class CalendarPageComponent implements OnInit { // alert(`Event clicked: ${clickInfo.event.extendedProps['id']}`); // const event = clickInfo.event as any; const entryId = clickInfo.event.extendedProps['id']; - console.log(entryId); this.router.navigate([`/entries/${entryId}`]); // Example: You can also access other event properties // console.log('Clicked event details:', clickInfo.event); 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 712f420..1300c04 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 @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { trigger, style, transition, animate } from '@angular/animations'; import { ActivatedRoute, Router } from '@angular/router'; @@ -16,13 +16,13 @@ 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'; import { EntrySeen } from '../../../shared/models/entry-seen.model'; import { EpisodeSeenModalComponent } from '../../../shared/components/modals/episode-seen-modal/episode-seen-modal.component'; import { MediaModalComponent } from '../media-modal/media-modal.component'; import { Collection } from '../../../shared/models/collection.model'; import { EntrySettingsModalComponent } from '../entry-settings-modal/entry-settings-modal.component'; import { ConfigService } from '../../../core/services/config.service'; +import { ToastService } from '../../../shared/services/toast.service'; @Component({ selector: 'app-entry-page', @@ -67,7 +67,7 @@ export class EntryPageComponent implements OnInit { private dialog: MatDialog, private route: ActivatedRoute, private router: Router, - private toastr: ToastrService + private toast: ToastService ) {} ngOnInit(): void { @@ -104,15 +104,10 @@ export class EntryPageComponent implements OnInit { }, error: (error) => { // console.log(`Couldn't fetch season episodes data:`, error); - this.toastr.success( + this.toast.show( 'Error', `Couldn't get season ${season.season_number} episodes.`, - { - tapToDismiss: true, - progressBar: true, - positionClass: 'bottom-right', - progressAnimation: 'increasing', - } + 'error' ); season.episodes = []; }, @@ -143,14 +138,13 @@ export class EntryPageComponent implements OnInit { .subscribe({ next: (entryRatings) => { if (entryRatings) { - // TODO show notification this.entry.entryRating = entryRatings; this.libraryService.updateEntry(this.entry); } }, error: (error) => { - // TODO show notification - console.error('Error updating entryRatings:', error); + this.toast.show('', `Error updating rating.`, 'error'); + // console.error('Error updating entryRatings:', error); }, }); } @@ -159,20 +153,20 @@ export class EntryPageComponent implements OnInit { openEntrySeenModal(entrySeen: EntrySeen = {} as EntrySeen) { if (!this.entry) return; - let oldData = {} as { watchDate: Date; watchedWith: string }; - if (entrySeen.id) { - oldData.watchDate = entrySeen.date_seen; - oldData.watchedWith = entrySeen.seen_with; - } const dialogRef = this.dialog.open(SeenModalComponent, { width: '360px', - data: oldData.watchDate ? oldData : {}, + data: entrySeen.id + ? { + watchDate: entrySeen.date_seen, + watchedWith: entrySeen.seen_with, + } + : {}, }); dialogRef.afterClosed().subscribe((result) => { if (result) { if (result.watchDate == '') { - // TODO show no was passed date notification + this.toast.show('', 'You did not provide a watch date.', 'error'); return; } @@ -189,7 +183,7 @@ export class EntryPageComponent implements OnInit { this.entrySeenService.updateEntrySeen(es).subscribe({ next: (updatedEntrySeen) => { - // TODO show confirm notification + this.toast.show('', 'Watch record updated.', 'success'); // ? replace the entry-seen object with the updated one for (let i = 0; i < this.entry.entrySeen.length; i++) { if (this.entry.entrySeen[i].id == updatedEntrySeen.id) { @@ -216,7 +210,8 @@ export class EntryPageComponent implements OnInit { } }, error: (error) => { - console.error('Error adding entrySeen:', error); + this.toast.show('', 'Error updating a watch record.', 'error'); + // console.error('Error updating entrySeen:', error); }, }); } else { @@ -226,7 +221,7 @@ export class EntryPageComponent implements OnInit { .subscribe({ next: (entrySeen) => { if (entrySeen) { - // TODO show confirm notification + this.toast.show('', 'Watch record created.', 'success'); this.entry.entrySeen.push(entrySeen); // ? if the entry was in watch list creating and entry-seen would have removed it @@ -253,12 +248,11 @@ export class EntryPageComponent implements OnInit { } }, error: (error) => { + this.toast.show('', 'Error creating a watch record.', 'error'); console.error('Error adding entrySeen:', error); }, }); } - - // TODO show notification } else { // console.log('Seen dialog was cancelled'); } @@ -285,7 +279,7 @@ export class EntryPageComponent implements OnInit { this.entrySeenService.removeEntrySeen(id).subscribe({ next: () => { - this.toastr.success('success', `Removed successfuly.`, { + this.toast.show('success', `Removed successfuly.`, 'success', { tapToDismiss: true, progressBar: true, positionClass: 'bottom-right', @@ -300,9 +294,11 @@ export class EntryPageComponent implements OnInit { this.entry.date_first_seen = null; this.entry.date_last_seen = null; } + + this.toast.show('', 'Watch record deleted.'); }, error: (error) => { - // TODO show notification + this.toast.show('', 'Error deleting watch record.', 'error'); console.error('Error deleting entrySeen:', error); }, }); @@ -366,7 +362,7 @@ export class EntryPageComponent implements OnInit { }); dialogRef.afterClosed().subscribe((result) => { - // TODO update entry page collections + // TODO * update entry page collections this.entryService.getEntryById(this.entry.id).subscribe({ next: (result) => { this.entry.collections = result.collections.map((c) => { @@ -440,16 +436,23 @@ export class EntryPageComponent implements OnInit { return c; }); // console.log(`Entry refreched: `, entry); - this.toastr.success(`Movie refreshed successfuly.`, 'Success', { - tapToDismiss: true, - progressBar: true, - positionClass: 'bottom-right', - progressAnimation: 'increasing', - }); + this.toast.show( + '', + `${ + this.entry.is_tvseries ? 'Tv-Serie' : 'Movie' + } info refreshed successfuly.`, + 'success' + ); }, error: (error) => { - // TODO show error notification - console.error('Error refreching movie info:', error); + this.toast.show( + '', + `Couln't refresh ${ + this.entry.is_tvseries ? 'Tv-Serie' : 'Movie' + } info.`, + 'error' + ); + // console.error('Error refreching movie info:', error); }, complete: () => { this.lockActions = false; @@ -460,10 +463,24 @@ export class EntryPageComponent implements OnInit { fetchEntryCollection() { this.lockActions = true; this.entryService.fetchEntryCollectionById(this.entry.id).subscribe({ - next: (result) => {}, + next: (result) => { + this.toast.show( + '', + `${ + this.entry.is_tvseries ? 'Tv-Serie' : 'Movie' + } info refreshed successfuly.`, + 'success' + ); + }, error: (error) => { - // TODO show error notification - console.error('Error refreching movie info:', error); + this.toast.show( + '', + `Couln't refresh ${ + this.entry.is_tvseries ? 'Tv-Serie' : 'Movie' + } info.`, + 'error' + ); + // console.error('Error refreching movie collection:', error); }, complete: () => { this.lockActions = false; @@ -547,7 +564,7 @@ export class EntryPageComponent implements OnInit { dialogRef.afterClosed().subscribe((result) => { // ? if an episode-seen was created then refresh the watch history table if (result && result.created) { - // TODO: improve this logic, there shouldn't be a need to whole recall + // TODO * improve this logic, there shouldn't be a need to whole recall // ? call this function to fetch the new episode-seen history this.getEpisodesSeenHistory(); @@ -580,15 +597,20 @@ export class EntryPageComponent implements OnInit { season.episodes = episodes; }, error: (error) => { - console.log(`Couldn't fetch season episodes data:`, error); - // TODO show notification - season.episodes = []; + this.toast.show( + '', + 'Error while adding episode watch record.', + 'error' + ); + // console.log(`Couldn't fetch season episodes data:`, error); + // season.episodes = []; }, }); } }); this.libraryService.updateEntry(this.entry); + this.toast.show('', 'Episode watch record created.', 'success'); } }); } @@ -627,6 +649,7 @@ export class EntryPageComponent implements OnInit { } this.libraryService.updateEntry(this.entry); + this.toast.show('', 'Episode watch record upated.', 'success'); } }); } @@ -676,19 +699,27 @@ export class EntryPageComponent implements OnInit { season.episodes = episodes; }, error: (error) => { - console.log(`Couldn't fetch season episodes data:`, error); - // TODO show notification - season.episodes = []; + this.toast.show( + '', + 'Error while deleting episode watch record.', + 'error' + ); + // console.log(`Couldn't fetch season episodes data:`, error); }, }); } }); this.libraryService.updateEntry(this.entry); - // TODO show notification + this.toast.show('', 'Episode watch record deleted.', 'success'); }, error: (error) => { - console.log(`Episode seen delete error: `, error); + this.toast.show( + '', + `Error while deleting episode watch record.`, + 'error' + ); + // console.log(`Episode seen delete error: `, error); }, }); } @@ -788,13 +819,7 @@ export class EntryPageComponent implements OnInit { }, }); - dialogRef.afterClosed().subscribe((result) => { - if (result) { - // TODO show notification - } else { - // console.log('Seen dialog was cancelled'); - } - }); + dialogRef.afterClosed().subscribe((result) => {}); } settingsModal() { @@ -810,13 +835,19 @@ export class EntryPageComponent implements OnInit { dialogRef.afterClosed().subscribe((result) => { if (result) { - this.entry.watchlist = result.entry.watchlist; - this.entry.favorit = result.entry.favorit; - this.entry.hidden = result.entry.hidden; - this.entry.showInCalendar = result.entry.showInCalendar; - this.entry.autoSync = result.entry.autoSync; + if (result.entry) { + this.entry.watchlist = result.entry.watchlist; + this.entry.favorit = result.entry.favorit; + this.entry.hidden = result.entry.hidden; + this.entry.showInCalendar = result.entry.showInCalendar; + this.entry.autoSync = result.entry.autoSync; - this.libraryService.updateEntry(this.entry); + this.libraryService.updateEntry(this.entry); + + this.toast.show('', `Settings updated.`, 'success'); + } else { + this.toast.show('', `Couldn't updated settings.`, 'error'); + } } }); } diff --git a/frontend/src/app/features/entry/entry-settings-modal/entry-settings-modal.component.ts b/frontend/src/app/features/entry/entry-settings-modal/entry-settings-modal.component.ts index 66a17c3..f1ad9a7 100644 --- a/frontend/src/app/features/entry/entry-settings-modal/entry-settings-modal.component.ts +++ b/frontend/src/app/features/entry/entry-settings-modal/entry-settings-modal.component.ts @@ -12,7 +12,7 @@ import { FormBuilder, FormGroup } from '@angular/forms'; templateUrl: './entry-settings-modal.component.html', styleUrls: ['./entry-settings-modal.component.css'], }) -export class EntrySettingsModalComponent implements OnInit { +export class EntrySettingsModalComponent { entryId!: number; entryForm: FormGroup; @@ -38,8 +38,6 @@ export class EntrySettingsModalComponent implements OnInit { } } - ngOnInit() {} - onSubmit() { const entryData = this.entryForm.value; @@ -48,7 +46,8 @@ export class EntrySettingsModalComponent implements OnInit { this.dialogRef.close({ entry: result }); }, error: (error) => { - console.log(error); + // console.log(`Error while updating entry settings`, error); + this.dialogRef.close(); }, }); } diff --git a/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.css b/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.css index 5294c51..2beb958 100644 --- a/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.css +++ b/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.css @@ -38,6 +38,5 @@ .footer-actions { display: flex; justify-content: flex-end; /* Moves button to the right */ - background: white; } diff --git a/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.ts b/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.ts index 6f1b8bf..f1f302b 100644 --- a/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.ts +++ b/frontend/src/app/shared/components/modals/list-selection-modal/user-collections-modal.component.ts @@ -50,7 +50,7 @@ export class UserCollectionsModalComponent implements OnInit { public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, private collectionService: CollectionService, - private toastService: ToastService + private toast: ToastService ) {} ngOnInit() { @@ -128,7 +128,7 @@ export class UserCollectionsModalComponent implements OnInit { .subscribe({ next: (response) => { // TODO TOAST entry added to collection - this.showNotification( + this.toast.show( 'Entry Added', 'Entry added successfully', 'success' @@ -138,7 +138,7 @@ export class UserCollectionsModalComponent implements OnInit { }, error: (error) => { console.error('Error:', error); - // this.showNotification('Error', 'Failed to add entry', 'error'); + this.toast.show('Error', 'Failed to add entry', 'error'); }, }); } else { @@ -149,16 +149,15 @@ export class UserCollectionsModalComponent implements OnInit { .removeEntryFromCollection(collection.id, this.entryId) .subscribe({ next: (result) => { - this.showNotification( + this.toast.show( 'Entry Removed', 'Entry removed successfully', 'success' ); - // TODO TOAST ENTRY REMOVE FROM COLLECTION }, error: (error) => { console.error('Error removing entry:', error); - this.showNotification('Error', 'Failed to remove entry', 'error'); + this.toast.show('Error', 'Failed to remove entry', 'error'); }, }); } @@ -171,9 +170,4 @@ export class UserCollectionsModalComponent implements OnInit { onSubmit(): void { this.dialogRef.close(); } - - showNotification(title: string, message: string, type: string): void { - // this.notificationComponent.showNotification(message, type); - this.toastService.show(title, message, type); - } } diff --git a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts index 31e85e1..00c5c0b 100644 --- a/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts +++ b/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts @@ -10,6 +10,12 @@ import { } from '@angular/animations'; import { formatDate } from '@angular/common'; +interface ModalInputs { + title?: string; + watchedWith?: string; + watchDate?: string; + hideSeenWith?: boolean; +} @Component({ selector: 'app-seen-modal', templateUrl: './seen-modal.component.html', @@ -33,7 +39,7 @@ import { formatDate } from '@angular/common'; ], }) export class SeenModalComponent implements OnInit { - title: string = 'Watch Details'; + title: string = 'Watch Record Details'; hideSeenWith: boolean = false; public watchDate: string = ''; @@ -41,7 +47,7 @@ export class SeenModalComponent implements OnInit { constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any + @Inject(MAT_DIALOG_DATA) public data: ModalInputs ) {} ngOnInit(): void { @@ -65,6 +71,8 @@ export class SeenModalComponent implements OnInit { 'yyyy-MM-dd', 'en-US' ); + } else { + this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US'); } } else { this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');