diff --git a/src/components/create-modal/create-edit-modal/create-edit-modal.component.ts b/src/components/create-modal/create-edit-modal/create-edit-modal.component.ts
index 6a7b561..caeac9d 100644
--- a/src/components/create-modal/create-edit-modal/create-edit-modal.component.ts
+++ b/src/components/create-modal/create-edit-modal/create-edit-modal.component.ts
@@ -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})
}
}
diff --git a/src/components/delete-modal/delete-modal.component.spec.ts b/src/components/delete-modal/delete-modal.component.spec.ts
index 7c29c0f..0bafd22 100644
--- a/src/components/delete-modal/delete-modal.component.spec.ts
+++ b/src/components/delete-modal/delete-modal.component.spec.ts
@@ -1,6 +1,6 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
+import {ComponentFixture, TestBed} from '@angular/core/testing';
-import { DeleteModalComponent } from './delete-modal.component';
+import {DeleteModalComponent} from './delete-modal.component';
describe('DeleteModalComponent', () => {
let component: DeleteModalComponent;
@@ -10,7 +10,7 @@ describe('DeleteModalComponent', () => {
await TestBed.configureTestingModule({
imports: [DeleteModalComponent]
})
- .compileComponents();
+ .compileComponents();
fixture = TestBed.createComponent(DeleteModalComponent);
component = fixture.componentInstance;
diff --git a/src/components/delete-modal/delete-modal.component.ts b/src/components/delete-modal/delete-modal.component.ts
index bb2085a..7726646 100644
--- a/src/components/delete-modal/delete-modal.component.ts
+++ b/src/components/delete-modal/delete-modal.component.ts
@@ -1,12 +1,6 @@
import {Component, inject} from '@angular/core';
import {NgbActiveModal, NgbCollapse} from '@ng-bootstrap/ng-bootstrap';
-import {
- FormControl,
- FormGroup,
- FormsModule,
- ReactiveFormsModule,
- Validators
-} from '@angular/forms';
+import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms';
@Component({
selector: 'app-delete-modal',
@@ -27,7 +21,7 @@ export class DeleteModalComponent {
constructor() {
this.confirmationForm = new FormGroup({
- name: new FormControl("",Validators.required)
+ name: new FormControl("", Validators.required)
})
}
diff --git a/src/pages/shows/shows.component.html b/src/pages/shows/shows.component.html
index 924e8b1..8f6cc94 100644
--- a/src/pages/shows/shows.component.html
+++ b/src/pages/shows/shows.component.html
@@ -9,7 +9,7 @@
-