Components/create-edit-modal: finish implementing
This commit is contained in:
parent
faac2fc2e2
commit
e35564735f
1 changed files with 50 additions and 16 deletions
|
|
@ -59,22 +59,56 @@ export class CreateEditModalComponent {
|
|||
//TODO: Allow user to specify genres
|
||||
genres: []
|
||||
}
|
||||
this.showsService.sendShow(show).subscribe({
|
||||
next: (response: ShowsApiCreation) => {
|
||||
show._id = response.newId
|
||||
}, error: err => {
|
||||
this.toastService.show({
|
||||
body: "Could not add show!",
|
||||
htmlClass: "bg-danger text-light"
|
||||
})
|
||||
console.error(err)
|
||||
}, complete: () => {
|
||||
this.toastService.show({
|
||||
body: "Show added successfully!",
|
||||
htmlClass: "bg-success text-light"
|
||||
})
|
||||
this.activeModal.close(show)
|
||||
|
||||
|
||||
if (!this.editMode) {
|
||||
this.showsService.sendShow(show).subscribe({
|
||||
next: (response: ShowsApiCreation) => {
|
||||
show._id = response.newId
|
||||
}, error: err => {
|
||||
this.showToast(true, "created")
|
||||
console.error(err)
|
||||
}, complete: () => {
|
||||
this.showToast(false, "created")
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue