Components/create-edit-modal: finish implementing

This commit is contained in:
Toast 2025-02-06 10:46:04 +01:00
parent faac2fc2e2
commit e35564735f

View file

@ -59,22 +59,56 @@ export class CreateEditModalComponent {
//TODO: Allow user to specify genres //TODO: Allow user to specify genres
genres: [] genres: []
} }
this.showsService.sendShow(show).subscribe({
next: (response: ShowsApiCreation) => {
show._id = response.newId if (!this.editMode) {
}, error: err => { this.showsService.sendShow(show).subscribe({
this.toastService.show({ next: (response: ShowsApiCreation) => {
body: "Could not add show!", show._id = response.newId
htmlClass: "bg-danger text-light" }, error: err => {
}) this.showToast(true, "created")
console.error(err) console.error(err)
}, complete: () => { }, complete: () => {
this.toastService.show({ this.showToast(false, "created")
body: "Show added successfully!", this.activeModal.close(show)
htmlClass: "bg-success text-light" }
}) })
this.activeModal.close(show) } else {
// The API requires the show to also have an ID, so
// I add it here
show._id = this.show?._id
this.showsService.updateShow(show).subscribe({
next: (response: ShowsApiDeletionEdit) => {
// Do nothing
}, error: err => {
this.showToast(true, "edited")
console.error(err)
}, complete: () => {
this.showToast(false, "edited")
this.activeModal.close(show)
}
})
}
}
private showToast(error: boolean, action: "edited" | "created") {
let htmlClass: string = "bg-success text-light"
let body: string;
if (error) {
htmlClass = htmlClass.replace("success", "danger")
let temp: string
switch (action){
case "created":
temp = "created"
break
case "edited":
temp = "edit"
break
} }
}) body = `Could not ${temp} show!`
} else {
body = `Show ${action} successfully!`
}
this.toastService.show({body,htmlClass})
} }
} }