import { h, Component } from 'preact'

import client from '../../../client.js'

export default class FileUploadButton 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
    client.upload(this.props.folder.id, files).then( got_files => {
      this.props.addFiles(got_files)
    })
  }
  render() {
    return (
      <div class='fileUploadButton'>
        <input type='file' multiple name='files' onChange={this.updateFiles} />
        <span>+ upload</span>
      </div>
    )
  }
}
