F: Added toast to entry-page and other components
This commit is contained in:
1 parent
d01913bb6d
commit
8533076080
6 files changed
+114
-84
No files matched your search
@@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+3
-4
@@ -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();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user