Skip to content

Commit

Permalink
USH-1684 - Edit posts with old image fields (#1478)
Browse files Browse the repository at this point in the history
* Bugs fixed
  • Loading branch information
ushahidlee authored Nov 21, 2024
1 parent d29a6bf commit 4e9ec7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class PostEditComponent extends BaseComponent implements OnInit, OnChange
}

private async handleUpload(key: string, value: any) {
if (!value[0].value) return;
if (!value?.[0]?.value) return;
try {
const response: any = await lastValueFrom(this.mediaService.getById(value[0].value));
this.form.patchValue({
Expand Down Expand Up @@ -662,23 +662,27 @@ export class PostEditComponent extends BaseComponent implements OnInit, OnChange
this.form.value[field.key]?.id,
);
await lastValueFrom(deleteObservable);
value.value = null;
value.value = [];
} catch (error: any) {
throw new Error(`Error deleting file: ${error.message}`);
}
} else if (originalValue?.value[0].caption !== value.value?.caption) {
} else if (
originalValue?.value?.length > 0 &&
originalValue.value[0].caption !== value.value.caption
) {
try {
const captionObservable = await this.mediaService.updateCaption(
originalValue.value[0].id,
originalValue.value[0].value,
value.value.caption,
);
await lastValueFrom(captionObservable);
value.value = [originalValue.value[0].id];
value.value = [originalValue.value[0].value];
} catch (error: any) {
throw new Error(`Error updating caption: ${error.message}`);
}
} else {
value.value = this.form.value[field.key]?.id || [];
if (this.form.value[field.key]) value.value = [this.form.value[field.key]?.id];
else value.value = [];
}
break;
case 'image':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PostPreviewComponent implements OnInit, OnChanges {
if (changes['post']) {
this.allowed_privileges = this.post?.allowed_privileges ?? '';

if (this.post.post_media) {
if (this.post.post_media && this.post.post_media.value.value) {
this.mediaService.getById(this.post.post_media.value.value).subscribe({
next: (media) => {
this.media = media.result;
Expand Down

0 comments on commit 4e9ec7e

Please sign in to comment.