summaryrefslogtreecommitdiff
path: root/client/components/Folder/FileUploadButton.jsx
blob: 8c7d1704cd425a91041c05120beaf8b6fe0806da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { h, Component } from 'preact'
import { Link } from 'react-router-dom'

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 = {
    }
    this.updateFiles = this.updateFiles.bind(this)
  }
  updateFiles(event){
    const name = event.target.name
    const files = event.target.files
    console.log(name, files)

    client.upload(this.props.folder.id, files).then( got_files => {
      console.log(got_files)
      this.props.addFiles(got_files)
    })
  }

  render() {
    console.log(this.props)
    const files = (this.props.folder.files || []).map( (file, i) => {
      return (
        <div key={i}>
          {file.name}
        </div>
      )
    })
    return (
      <div class='fileUploadButton'>
        <input type='file' multiple name='files' onChange={this.updateFiles} />
        <span>+ file</span>
      </div>
    )
  }
}