From a7465a66cd49a943b725f0a3ef45d0b1511b48db Mon Sep 17 00:00:00 2001
From: Jules Laplace <julescarbon@gmail.com>
Date: Thu, 29 Jun 2017 04:03:58 +0200
Subject: upload files

---
 client/components/Folder/Folder.jsx | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

(limited to 'client/components/Folder/Folder.jsx')

diff --git a/client/components/Folder/Folder.jsx b/client/components/Folder/Folder.jsx
index 891451c..e39b40d 100644
--- a/client/components/Folder/Folder.jsx
+++ b/client/components/Folder/Folder.jsx
@@ -5,34 +5,36 @@ import Modal from '../Modal.jsx'
 
 import client from '../../client.js'
 
+import FileUploadButton from './FileUploadButton.jsx'
+
 export default class Folder extends Component {
   constructor(props) {
     super()
     this.state = {
-      adding: false,
+      files: props.folder.files || [],
     }
+    this.addFiles = this.addFiles.bind(this)
   }
-  toggle(folder) {
-    folder.open = ! folder.open
-    if (folder.open && ! folder.files) {
-      client.files.index({ 'folder_id': folder.id }).then( files => {
-        this.props.openFolder(folder)
-      })
-    }
+  addFiles(newFiles) {
+    console.log(newFiles)
+    if (! newFiles) return
+    const files = this.state.files.concat(newFiles).sort( (a,b) => { return b.id - a.id } )
+    this.setState({ files })
   }
   render() {
     console.log(this.props)
-    const folders = (this.props.folders || []).map( (folder,i) => {
+    const files = (this.state.files).map( (file, i) => {
+      if (! file) return
       return (
-        <div key={i} onClick={() => this.toggle(folder)}>
-          {folder.name}
+        <div key={i}>
+          {file.name}
         </div>
       )
     })
     return (
       <div class='folders'>
-        <b>{this.props.folder.name}</b> <button onClick={() => {}}>+ file</button>
-        {folders}
+        <b>{this.props.folder.name}</b> <FileUploadButton folder={this.props.folder} addFiles={this.addFiles} />
+        {files}
       </div>
     )
   }
-- 
cgit v1.2.3-70-g09d2

