aboutsummaryrefslogtreecommitdiffstats
path: root/app/javascript/activetext/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/activetext/index.js')
-rw-r--r--app/javascript/activetext/index.js33
1 files changed, 5 insertions, 28 deletions
diff --git a/app/javascript/activetext/index.js b/app/javascript/activetext/index.js
index e1c59dd50d..c149eda952 100644
--- a/app/javascript/activetext/index.js
+++ b/app/javascript/activetext/index.js
@@ -1,34 +1,11 @@
import * as Trix from "trix"
-import { DirectUpload } from "activestorage"
+import { AttachmentUpload } from "./attachment_upload"
addEventListener("trix-attachment-add", event => {
- const { attachment } = event
- if (!attachment.file) return
+ const { attachment, target } = event
- const { directUploadUrl, blobUrlTemplate } = event.target.dataset
-
- const delegate = {
- directUploadWillStoreFileWithXHR: (xhr) => {
- xhr.upload.addEventListener("progress", event => {
- const progress = event.loaded / event.total * 100
- attachment.setUploadProgress(progress)
- })
- }
+ if (attachment.file) {
+ const upload = new AttachmentUpload(attachment, target)
+ upload.start()
}
-
- const directUpload = new DirectUpload(attachment.file, directUploadUrl, delegate)
-
- directUpload.create((error, attributes) => {
- if (error) {
- console.warn("Failed to store file for attachment", attachment, error)
- } else {
- const sgid = attributes.attachable_sgid
-
- const url = blobUrlTemplate
- .replace(":signed_id", attributes.signed_id)
- .replace(":filename", encodeURIComponent(attributes.filename))
-
- attachment.setAttributes({ sgid, url })
- }
- })
})