Browse Source

addFile, addMeta (WIP)

Artur Paikin 9 years ago
parent
commit
fe769cf622
2 changed files with 50 additions and 12 deletions
  1. 37 0
      src/core/Core.js
  2. 13 12
      src/plugins/DragDrop.js

+ 37 - 0
src/core/Core.js

@@ -88,6 +88,43 @@ export default class Core {
     reader.readAsDataURL(file.data)
   }
 
+  addMeta (meta, file) {
+    if (typeof file === 'undefined') {
+      const updatedFiles = Object.assign({}, this.state.files)
+      for (let f in updatedFiles) {
+        updatedFiles[f].meta = meta
+      }
+      this.setState({files: updatedFiles})
+    }
+  }
+
+  addFile (fileData, fileName, fileType, caller) {
+    const updatedFiles = Object.assign({}, this.state.files)
+
+    fileType = fileType.split('/')
+    const fileTypeGeneral = fileType[0]
+    const fileTypeSpecific = fileType[1]
+    const fileID = Utils.generateFileID(fileName)
+
+    updatedFiles[fileID] = {
+      acquiredBy: caller,
+      id: fileID,
+      name: fileName,
+      type: {
+        general: fileTypeGeneral,
+        specific: fileTypeSpecific
+      },
+      data: fileData,
+      progress: 0
+    }
+
+    this.setState({files: updatedFiles})
+
+    if (this.opts.autoProceed) {
+      this.emitter.emit('next')
+    }
+  }
+
   addFiles (files, caller) {
     const updatedFiles = Object.assign({}, this.state.files)
 

+ 13 - 12
src/plugins/DragDrop.js

@@ -38,15 +38,6 @@ export default class DragDrop extends Plugin {
     this.handleInputChange = this.handleInputChange.bind(this)
   }
 
-  update (state) {
-    if (typeof this.el === 'undefined') {
-      return
-    }
-
-    const newEl = this.render(this.core.state)
-    yo.update(this.el, newEl)
-  }
-
 /**
  * Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
  * @return {Boolean} true if supported, false otherwise
@@ -72,10 +63,20 @@ export default class DragDrop extends Plugin {
   handleDrop (files) {
     this.core.log('All right, someone dropped something...')
 
-    this.core.emitter.emit('file-add', {
-      plugin: this,
-      acquiredFiles: files
+    // this.core.emitter.emit('file-add', {
+    //   plugin: this,
+    //   acquiredFiles: files
+    // })
+
+    files.forEach((file) => {
+      const fileName = file.name
+      const fileType = file.type
+      const fileData = file
+      this.core.addFile(fileData, fileName, fileType, this)
     })
+
+    this.core.addMeta({bla: 'bla'})
+    console.log(this.core.getState())
   }
 
   handleInputChange (ev) {