From a52a76b6d0b28a8ad2ab957a559722ceaf1b5596 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 6 Feb 2025 19:17:51 +0100 Subject: [PATCH] Components/create-edit-modal: send and recieve images from api --- .../create-edit-modal.component.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/create-edit-modal/create-edit-modal.component.ts b/src/components/create-edit-modal/create-edit-modal.component.ts index 91864f8..2700659 100644 --- a/src/components/create-edit-modal/create-edit-modal.component.ts +++ b/src/components/create-edit-modal/create-edit-modal.component.ts @@ -45,7 +45,13 @@ export class CreateEditModalComponent { images: new FormArray([]) }) - this.addImageControl() + if (this.show?.images !== undefined) { + this.show?.images.forEach((imageUrl: string) => { + this.addImageControl(imageUrl) + }) + } else { + this.addImageControl() + } } get images(): FormArray { @@ -56,9 +62,9 @@ export class CreateEditModalComponent { this.activeModal.dismiss() } - protected addImageControl() { + protected addImageControl(value: string = "") { const urlRegex: string = '(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?' - this.images.push(new FormControl("", [Validators.required, Validators.pattern(urlRegex)])) + this.images.push(new FormControl(value, [Validators.required, Validators.pattern(urlRegex)])) } protected removeImageControl(index: number) { @@ -72,11 +78,11 @@ export class CreateEditModalComponent { seasons: form.get("seasons")?.value, episodes: form.get("episodes")?.value, description: form.get("description")?.value, + images: form.get("images")?.value, //TODO: Allow user to specify genres genres: [] } - if (!this.editMode) { this.showsService.sendShow(show).subscribe({ next: (response: ShowsApiCreation) => {