From: Cyperghost Date: Wed, 18 Dec 2024 09:53:22 +0000 (+0100) Subject: Notify only when the value has really changed. X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4150800bc83a9590c76f9d83aad086144ca21f86;p=GitHub%2FWoltLab%2FWCF.git Notify only when the value has really changed. --- diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts index b618c51c0c..724d6fd748 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts @@ -88,7 +88,7 @@ export class FileProcessor { this.#fileInput = this.#uploadButton.querySelector('input[type="file"]')!; this.#container.querySelectorAll("woltlab-core-file").forEach((element) => { - this.#registerFile(element, element.parentElement); + this.#registerFile(element, element.parentElement, false); }); fileProcessors.set(fieldId, this); @@ -168,7 +168,7 @@ export class FileProcessor { }; const cancelEventListener = () => { this.#uploadButton.dataset.context = oldContext; - this.#registerFile(this.#replaceElement!); + this.#registerFile(this.#replaceElement!, null, false); this.#replaceElement = undefined; this.#uploadResolve = undefined; this.#fileInput.removeEventListener("change", changeEventListener); @@ -223,7 +223,7 @@ export class FileProcessor { const cropCancelledEvent = () => { this.#uploadResolve = undefined; this.#uploadButton.dataset.context = oldContext; - this.#registerFile(this.#replaceElement!); + this.#registerFile(this.#replaceElement!, null, false); this.#replaceElement = undefined; }; @@ -261,7 +261,11 @@ export class FileProcessor { } } - #registerFile(element: WoltlabCoreFileElement, container: HTMLElement | null = null): void { + #registerFile( + element: WoltlabCoreFileElement, + container: HTMLElement | null = null, + notifyCallback: boolean = true, + ): void { if (container === null) { if (this.#useBigPreview) { container = this.#container.querySelector(".fileUpload__preview"); @@ -290,11 +294,11 @@ export class FileProcessor { void deleteFile(this.#replaceElement.fileId!); this.#replaceElement = undefined; } - this.#fileInitializationCompleted(element, container!); + this.#fileInitializationCompleted(element, container!, notifyCallback); }) .catch((reason) => { if (this.#replaceElement !== undefined) { - this.#registerFile(this.#replaceElement); + this.#registerFile(this.#replaceElement, null, false); this.#replaceElement = undefined; if (this.#useBigPreview) { @@ -313,7 +317,11 @@ export class FileProcessor { }); } - #fileInitializationCompleted(element: WoltlabCoreFileElement, container: HTMLElement): void { + #fileInitializationCompleted( + element: WoltlabCoreFileElement, + container: HTMLElement, + notifyCallback: boolean = true, + ): void { if (this.#useBigPreview) { setThumbnail( element, @@ -361,7 +369,9 @@ export class FileProcessor { this.addButtons(container, element); - notifyValueChange(this.#fieldId, this.values); + if (notifyCallback) { + notifyValueChange(this.#fieldId, this.values); + } } get values(): undefined | number | Set { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js index e9ce9108d5..f32fe5bbc9 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js @@ -57,7 +57,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui }); this.#fileInput = this.#uploadButton.querySelector('input[type="file"]'); this.#container.querySelectorAll("woltlab-core-file").forEach((element) => { - this.#registerFile(element, element.parentElement); + this.#registerFile(element, element.parentElement, false); }); fileProcessors.set(fieldId, this); } @@ -124,7 +124,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui }; const cancelEventListener = () => { this.#uploadButton.dataset.context = oldContext; - this.#registerFile(this.#replaceElement); + this.#registerFile(this.#replaceElement, null, false); this.#replaceElement = undefined; this.#uploadResolve = undefined; this.#fileInput.removeEventListener("change", changeEventListener); @@ -170,7 +170,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui const cropCancelledEvent = () => { this.#uploadResolve = undefined; this.#uploadButton.dataset.context = oldContext; - this.#registerFile(this.#replaceElement); + this.#registerFile(this.#replaceElement, null, false); this.#replaceElement = undefined; }; this.#uploadButton.addEventListener("cancel", cropCancelledEvent, { once: true }); @@ -202,7 +202,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui element.parentElement.parentElement.remove(); } } - #registerFile(element, container = null) { + #registerFile(element, container = null, notifyCallback = true) { if (container === null) { if (this.#useBigPreview) { container = this.#container.querySelector(".fileUpload__preview"); @@ -229,11 +229,11 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui void (0, DeleteFile_1.deleteFile)(this.#replaceElement.fileId); this.#replaceElement = undefined; } - this.#fileInitializationCompleted(element, container); + this.#fileInitializationCompleted(element, container, notifyCallback); }) .catch((reason) => { if (this.#replaceElement !== undefined) { - this.#registerFile(this.#replaceElement); + this.#registerFile(this.#replaceElement, null, false); this.#replaceElement = undefined; if (this.#useBigPreview) { // `this.#replaceElement` need a new container, otherwise the element will be marked as erroneous, too. @@ -249,7 +249,7 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui (0, Helper_1.removeUploadProgress)(container); }); } - #fileInitializationCompleted(element, container) { + #fileInitializationCompleted(element, container, notifyCallback = true) { if (this.#useBigPreview) { setThumbnail(element, element.thumbnails.find((thumbnail) => thumbnail.identifier === this.#thumbnailSize), true); } @@ -286,7 +286,9 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui input.value = element.fileId.toString(); container.append(input); this.addButtons(container, element); - notifyValueChange(this.#fieldId, this.values); + if (notifyCallback) { + notifyValueChange(this.#fieldId, this.values); + } } get values() { if (this.#singleFileUpload) {