Skip to content

Commit c98eca0

Browse files
committed
fix: use 'value' directly instead of saving the src into a new state
1 parent 258cebe commit c98eca0

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/packages/media/media/components/input-upload-field/input-upload-field.element.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ import { stringOrStringArrayContains } from '@umbraco-cms/backoffice/utils';
2727
export class UmbInputUploadFieldElement extends UmbLitElement {
2828
@property({ type: Object })
2929
set value(value: MediaValueType) {
30-
if (!value?.src) return;
31-
this.src = value.src;
30+
this.#src = value?.src ?? '';
3231
}
3332
get value(): MediaValueType {
34-
return !this.temporaryFile ? { src: this._src } : { temporaryFileId: this.temporaryFile.temporaryUnique };
33+
return {
34+
src: this.#src,
35+
temporaryFileId: this.temporaryFile?.temporaryUnique,
36+
};
3537
}
3638

39+
#src = '';
40+
3741
/**
3842
* @description Allowed file extensions. Allow all if empty.
3943
* @type {Array<string>}
@@ -50,17 +54,6 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
5054
@state()
5155
public temporaryFile?: UmbTemporaryFileModel;
5256

53-
public set src(src: string) {
54-
this._src = src;
55-
this._previewAlias = this.#getPreviewElementAlias();
56-
}
57-
public get src() {
58-
return this._src;
59-
}
60-
61-
@state()
62-
private _src = '';
63-
6457
@state()
6558
private _extensions?: string[];
6659

@@ -162,7 +155,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
162155

163156
const reader = new FileReader();
164157
reader.onload = () => {
165-
this.src = reader.result as string;
158+
this.value = { src: reader.result as string };
166159
};
167160
reader.readAsDataURL(item.file);
168161

@@ -180,8 +173,8 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
180173
}
181174

182175
override render() {
183-
if (this.src && this._previewAlias) {
184-
return this.#renderFile(this.src, this._previewAlias, this.temporaryFile?.file);
176+
if (this.value.src && this._previewAlias) {
177+
return this.#renderFile(this.value.src, this._previewAlias, this.temporaryFile?.file);
185178
} else {
186179
return this.#renderDropzone();
187180
}
@@ -200,7 +193,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
200193
`;
201194
}
202195

203-
#renderFile(src: string, previewAlias?: string, file?: File) {
196+
#renderFile(src: string, previewAlias: string, file?: File) {
204197
if (!previewAlias) return 'An error occurred. No previewer found for the file type.';
205198
return html`
206199
<div id="wrapper">
@@ -226,7 +219,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
226219
}
227220

228221
#handleRemove() {
229-
this.src = '';
222+
this.value = { src: undefined };
230223
this.temporaryFile = undefined;
231224
this.dispatchEvent(new UmbChangeEvent());
232225
}

0 commit comments

Comments
 (0)