diff --git a/assets/controllers/filedropzone_controller.js b/assets/controllers/filedropzone_controller.js deleted file mode 100644 index 4e28a5a..0000000 --- a/assets/controllers/filedropzone_controller.js +++ /dev/null @@ -1,42 +0,0 @@ -// filedropzone_controller.js - -import { Controller } from '@hotwired/stimulus'; -import axios from 'axios'; - -export default class extends Controller { - connect() { - this.element.addEventListener('dropzone:connect', this._onConnect); - this.element.addEventListener('dropzone:change', this._onChange); - this.element.addEventListener('dropzone:clear', this._onClear); - } - - disconnect() { - // You should always remove listeners when the controller is disconnected to avoid side-effects - this.element.removeEventListener('dropzone:connect', this._onConnect); - this.element.removeEventListener('dropzone:change', this._onChange); - this.element.removeEventListener('dropzone:clear', this._onClear); - } - - _onConnect(event) { - // The dropzone was just created - console.info('onconnect'); - } - - _onChange(event) { - // The dropzone just changed - console.info('onchange'); - axios.post(document.URL, new FormData(event.target.closest('form')), { - headers: { - 'Content-Type': 'multipart/form-data' - } - }).then(() => { - event.target.querySelector('.dropzone-preview-button').click(); - window.EventBus.$emit('fileUploaded'); - }) - } - - _onClear(event) { - // The dropzone has just been cleared - console.info('onclear'); - } -} \ No newline at end of file diff --git a/assets/js/api/book.js b/assets/js/api/book.js index ab20e5d..03a7748 100644 --- a/assets/js/api/book.js +++ b/assets/js/api/book.js @@ -8,8 +8,6 @@ export default { }) }, bookUpdateProgress(bookId, progress) { - console.info(bookId); - console.info(progress); return axios.post('/progress/update', { bookId: bookId, progress: progress diff --git a/assets/js/api/file.js b/assets/js/api/file.js new file mode 100644 index 0000000..a963032 --- /dev/null +++ b/assets/js/api/file.js @@ -0,0 +1,20 @@ +import axios from 'axios'; + +export default { + deleteFile: function (fileId) { + return axios.get(window.location.origin + '/file/delete/' + fileId); + }, + getFiles: function (bookId) { + return axios.get(this.getFilesEndpoint(bookId), { + headers: { + 'accept': 'application/json' + } + }); + }, + getFilesEndpoint: function (bookId) { + if (bookId) { + return `/api/books/${bookId}/files`; + } + return `/api/files`; + } +} \ No newline at end of file diff --git a/assets/js/event-bus.js b/assets/js/event-bus.js deleted file mode 100644 index 0b39f8e..0000000 --- a/assets/js/event-bus.js +++ /dev/null @@ -1,3 +0,0 @@ -import Vue from 'vue'; -window.EventBus = new Vue(); -export const EventBus = window.EventBus; \ No newline at end of file diff --git a/assets/js/pages/files.vue b/assets/js/pages/files.vue index 967dfa0..a7c6844 100644 --- a/assets/js/pages/files.vue +++ b/assets/js/pages/files.vue @@ -25,54 +25,63 @@ {{ file.file_size_human }} {{ file.extension }} download - remove + remove + +
+

Drag and drop to upload content!

+
+ ...or click to select a file from your computer +
+
+