diff --git a/app/assets/javascripts/discourse/app/components/emoji-uploader.hbs b/app/assets/javascripts/admin/addon/components/emoji-uploader.hbs similarity index 89% rename from app/assets/javascripts/discourse/app/components/emoji-uploader.hbs rename to app/assets/javascripts/admin/addon/components/emoji-uploader.hbs index 713977b0ffe..1af35f505fc 100644 --- a/app/assets/javascripts/discourse/app/components/emoji-uploader.hbs +++ b/app/assets/javascripts/admin/addon/components/emoji-uploader.hbs @@ -33,8 +33,9 @@
diff --git a/app/assets/javascripts/discourse/app/components/emoji-uploader.js b/app/assets/javascripts/admin/addon/components/emoji-uploader.js similarity index 55% rename from app/assets/javascripts/discourse/app/components/emoji-uploader.js rename to app/assets/javascripts/admin/addon/components/emoji-uploader.js index 501332a7885..abaac0320b9 100644 --- a/app/assets/javascripts/discourse/app/components/emoji-uploader.js +++ b/app/assets/javascripts/admin/addon/components/emoji-uploader.js @@ -1,16 +1,45 @@ import Component from "@ember/component"; import { action } from "@ember/object"; import { notEmpty } from "@ember/object/computed"; +import { getOwner } from "@ember/owner"; import { isEmpty } from "@ember/utils"; -import UppyUploadMixin from "discourse/mixins/uppy-upload"; +import UppyUpload from "discourse/lib/uppy/uppy-upload"; import discourseComputed from "discourse-common/utils/decorators"; import I18n from "discourse-i18n"; - const DEFAULT_GROUP = "default"; -export default class EmojiUploader extends Component.extend(UppyUploadMixin) { - type = "emoji"; - uploadUrl = "/admin/customize/emojis"; +export default class EmojiUploader extends Component { + uppyUpload = new UppyUpload(getOwner(this), { + id: "emoji-uploader", + type: "emoji", + uploadUrl: "/admin/customize/emojis", + preventDirectS3Uploads: true, + validateUploadedFilesOptions: { + imagesOnly: true, + }, + + perFileData: () => { + const payload = {}; + + if (!isEmpty(this.name)) { + payload.name = this.name; + + // if uploading multiple files, we can't use the name for every emoji + this.set("name", null); + } + + if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) { + payload.group = this.group; + } + + return payload; + }, + + uploadDone: (upload) => { + this.done(upload, this.group); + this.set("name", null); + }, + }); @notEmpty("name") hasName; @notEmpty("group") hasGroup; @@ -19,7 +48,6 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) { emojiGroups = null; newEmojiGroups = null; tagName = null; - preventDirectS3Uploads = true; didReceiveAttrs() { super.didReceiveAttrs(...arguments); @@ -38,38 +66,12 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) { }); } - _perFileData() { - const payload = {}; - - if (!isEmpty(this.name)) { - payload.name = this.name; - - // if uploading multiple files, we can't use the name for every emoji - this.set("name", null); - } - - if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) { - payload.group = this.group; - } - - return payload; - } - - validateUploadedFilesOptions() { - return { imagesOnly: true }; - } - - uploadDone(upload) { - this.done(upload, this.group); - this.set("name", null); - } - @action chooseFiles() { - this.fileInputEl.click(); + this.uppyUpload.openPicker(); } - @discourseComputed("uploading", "uploadProgress") + @discourseComputed("uppyUpload.uploading", "uppyUpload.uploadProgress") buttonLabel(uploading, uploadProgress) { if (uploading) { return `${I18n.t("admin.emoji.uploading")} ${uploadProgress}%`; @@ -78,7 +80,7 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) { } } - @discourseComputed("uploading") + @discourseComputed("uppyUpload.uploading") buttonIcon(uploading) { if (uploading) { return "spinner"; diff --git a/app/assets/javascripts/admin/addon/templates/emojis.hbs b/app/assets/javascripts/admin/addon/templates/emojis.hbs index 4d8a20e20a4..db7773ca1cb 100644 --- a/app/assets/javascripts/admin/addon/templates/emojis.hbs +++ b/app/assets/javascripts/admin/addon/templates/emojis.hbs @@ -15,7 +15,6 @@