Skip to content

Commit 304da88

Browse files
loivseniOvergaard
authored andcommitted
overwrite array, fix issue with checking for matches
1 parent 22c1ce0 commit 304da88

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
1919

2020
import { UmbExtensionsManifestInitializer } from '@umbraco-cms/backoffice/extension-api';
2121
import { type ManifestFileUploadPreview, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
22-
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
2322

2423
@customElement('umb-input-upload-field')
2524
export class UmbInputUploadFieldElement extends UmbLitElement {
@@ -70,14 +69,12 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
7069

7170
#manager = new UmbTemporaryFileManager(this);
7271

73-
#previewers = new UmbArrayState(<Array<ManifestFileUploadPreview>>[], (x) => x.alias);
72+
#previewers: Array<ManifestFileUploadPreview> = [];
7473

7574
constructor() {
7675
super();
7776
new UmbExtensionsManifestInitializer(this, umbExtensionsRegistry, 'fileUploadPreview', null, (previews) => {
78-
previews.forEach((preview) => {
79-
this.#previewers.appendOne(preview.manifest);
80-
});
77+
this.#previewers = previews.map((preview) => preview.manifest);
8178
});
8279
}
8380

@@ -91,25 +88,29 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
9188
}
9289

9390
#getPreviewElementAlias() {
94-
const previews = this.#previewers.getValue();
95-
const fallbackAlias = previews.find((preview) => preview.forMimeTypes.includes('*/*'))?.alias;
91+
const fallbackAlias = this.#previewers.find((preview) => preview.forMimeTypes.includes('*/*'))?.alias;
9692

9793
const mimeType = this.#getMimeTypeFromPath(this._src);
9894
if (!mimeType) return fallbackAlias;
9995

100-
const manifest = previews.find((preview) => {
101-
return preview.forMimeTypes?.find((type) => {
102-
if (mimeType === type) preview.alias;
96+
// Check for an exact match
97+
const exactMatch = this.#previewers.find((preview) => {
98+
return preview.forMimeTypes.find((type) => type === mimeType);
99+
});
100+
if (exactMatch) return exactMatch.alias;
103101

102+
// Check for wildcard match (e.g. image/*)
103+
const wildcardMatch = this.#previewers.find((preview) => {
104+
return preview.forMimeTypes.find((type) => {
104105
const snippet = type.replace(/\*/g, '');
105-
106106
if (mimeType.startsWith(snippet)) return preview.alias;
107107
if (mimeType.endsWith(snippet)) return preview.alias;
108108
return undefined;
109109
});
110110
});
111+
if (wildcardMatch) return wildcardMatch.alias;
111112

112-
if (manifest) return manifest.alias;
113+
// Use fallbackAlias.
113114
return fallbackAlias;
114115
}
115116

0 commit comments

Comments
 (0)