summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/editor/align/components/sidebar/waveUpload.component.js
blob: 68ef1e0d213b462daef6888a1e6a150201f438ac (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from 'react'
// import { Link } from 'react-router-dom'
import { connect } from 'react-redux'

// import actions from 'app/actions'

class WaveUpload extends Component {
  state = {
    working: false,
    status: "",
  }

  upload(e) {
    e.preventDefault()
    document.body.className = ''
    const files = e.dataTransfer ? e.dataTransfer.files : e.target.files
    let i
    let file
    for (i = 0; i < files.length; i++) {
      file = files[i]
      if (file && file.type.match('image.*')) break
    }
    if (!file) {
      console.log('No file specified')
      return
    }
    this.setState({ working: true, status: "Loading" })
    const fileReader = new FileReader()
    fileReader.onload = fileReaderEvent => {
      fileReader.onload = null
      this.processAudioFile({ file })
    }
    fileReader.readAsDataURL(file)
  }

  processAudioFile(file) {
    var context = new (window.AudioContext);
    source = context.createBufferSource();
  }

  render() {
    const { episode, peaks } = this.props
    return (
      <div className="sidebar-content wave-upload">
        {peaks.length && (
          <div>
            Peaks: {peaks.length}
          </div>
        )}
        <div className="uploadButton">
          <button>
            <span>
              {episode.settings.audio
                ? "Upload a new audio file"
                : "Upload an audio file"
              }
            </span>
          </button>
          <input
            type="file"
            accept="audio/mp3"
            onChange={this.upload.bind(this)}
            required={this.props.required}
          />
        </div>
        <small>Upload an MP3, encoded 192kbit constant bitrate, 44.1kHz stereo</small>
        <div>
          {this.state.status}
        </div>
      </div>
    )
  }
}

const mapStateToProps = state => ({
  peaks: state.align.peaks,
  episode: state.site.episode,
})

export default connect(mapStateToProps)(WaveUpload)