F: Added toast to entry-page and other components

This commit is contained in:
X4Lo committed 2025-04-13 03:54:55 +01:00
1 parent d01913bb6d
commit 8533076080
6 files changed
+114 -84

No files matched your search

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