Skip to content

Commit

Permalink
Get rid of FileUploader component (along w/ ember-uploader package) (#…
Browse files Browse the repository at this point in the history
…408)

* Get rid of FileUploader component

* u-edit/shared-modules/drag-and-drop: use our own uploader service to perform uploads

* get rid of ember-uploader

* prevent ember-cli-code-coverage babel plugin setup from leaking when parent runs tests w/ COVERAGE=true

* fix context

* linter fix
  • Loading branch information
phndiaye authored Dec 23, 2024
1 parent 768c19c commit 0425db6
Show file tree
Hide file tree
Showing 15 changed files with 2,038 additions and 743 deletions.
30 changes: 0 additions & 30 deletions addon/components/file-uploader.hbs

This file was deleted.

181 changes: 0 additions & 181 deletions addon/components/file-uploader.js

This file was deleted.

10 changes: 0 additions & 10 deletions addon/components/input-uploader/component.js

This file was deleted.

56 changes: 21 additions & 35 deletions addon/components/u-edit/shared-modules/drag-and-drop.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import Uploader from '@upfluence/ember-upf-utils/uploader';
import Configuration from '@upfluence/ember-upf-utils/configuration';

export default class ModuleBuilder {
constructor(session, toast) {
Object.assign(this, { session, toast });
constructor(uploader, toast) {
Object.assign(this, { uploader, toast });
}

build(editor, element) {
return new Module(editor, element, this.session, this.toast);
return new Module(editor, element, this.uploader, this.toast);
}
}

class Module {
constructor(editor, element, session, toast) {
Object.assign(this, { editor, element, session, toast });
constructor(editor, element, uploader, toast) {
Object.assign(this, { editor, element, uploader, toast });

this.editor.registerModule(this);

Expand All @@ -22,35 +21,17 @@ class Module {
};
}

_uploaderBuilder() {
let uploader = Uploader.create({
ajaxSettings: {
dataType: 'json',
headers: {
...this.uploaderHeaders,
Authorization: `Bearer ${this.session.data.authenticated.access_token}`
}
},
url: Configuration.uploaderUrl,
allowedExtensions: 'jpg,jpeg,png,gif',
maxSize: null
});

uploader
.on('didValidationError', (error) => {
this.toast.error(error || 'Your file is invalid. Please check the requirements.');
this._removeLoadingState();
})
.on('didUpload', (element) => {
this.editor.insertImage(element.artifact.url);
this._removeLoadingState();
});

return uploader;
}

_uploadFile(file) {
this._uploaderBuilder().upload(file, { privacy: 'public' });
this.uploader.upload(
{
file: file,
privacy: 'public',
scope: 'anonymous',
onSuccess: this._onSuccess.bind(this),
onFailure: this._removeLoadingState
},
[{ type: 'filetype', value: ['image', 'gif'] }]
);
}

_createLoadingStates() {
Expand Down Expand Up @@ -90,9 +71,14 @@ class Module {
document.querySelector('.uedit__loading-image-upload').classList.add('uedit__loading-image-upload--hidden');
}

_onSuccess(artifact) {
this.editor.insertImage(artifact.url);
this._removeLoadingState();
}

onImageUpload(files) {
this._addLoadingStates();
Array.prototype.forEach.call(files, (file) => this._uploadFile(file));
Array.from(files || []).forEach((file) => this._uploadFile(file));
}

getOptions() {
Expand Down
Loading

0 comments on commit 0425db6

Please sign in to comment.