diff options
| author | lens <lens@neural.garden> | 2021-03-23 21:10:11 +0000 |
|---|---|---|
| committer | lens <lens@neural.garden> | 2021-03-23 21:10:11 +0000 |
| commit | cc1d0c52e104245f9f1c0d77eb24a5a33800be38 (patch) | |
| tree | 02d8483dfe47803525b926a43c582dcfbf61c5db /frontend/app/views/audio/components/audio.select.js | |
| parent | 81c673f058fda04b96baae7b2302f876479bc0a9 (diff) | |
| parent | 7a3ec205e001e4c071a67ecc5c375612fa72afdc (diff) | |
Merge branch 'master' of asdf.us:swimmer
Diffstat (limited to 'frontend/app/views/audio/components/audio.select.js')
| -rw-r--r-- | frontend/app/views/audio/components/audio.select.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/frontend/app/views/audio/components/audio.select.js b/frontend/app/views/audio/components/audio.select.js new file mode 100644 index 0000000..384bb7a --- /dev/null +++ b/frontend/app/views/audio/components/audio.select.js @@ -0,0 +1,58 @@ +import React, { Component } from 'react' +import { connect } from 'react-redux' + +import { Select } from 'app/common' +import { unslugify } from 'app/utils' + +const NO_AUDIO = 0 +const AUDIO_TOP_OPTIONS = [ + { name: NO_AUDIO, label: 'No Sound' }, + { name: -2, label: '──────────', disabled: true }, +] + +class AudioSelect extends Component { + state = { + audioList: [] + } + + constructor(props) { + super(props) + this.handleChange = this.handleChange.bind(this) + } + + componentDidMount(){ + const { uploads } = this.props.graph.show.res + const audioUploads = uploads + .filter(upload => upload.tag === 'audio') + .map(upload => ({ name: upload.id, label: unslugify(upload.fn) })) + let audioList = [ + ...AUDIO_TOP_OPTIONS, + ...audioUploads, + ] + this.setState({ + audioList, + }) + } + + handleChange(name, value) { + this.props.onChange(name, parseInt(value)) + } + + render() { + return ( + <Select + title={this.props.title || "Audio"} + name={this.props.name} + selected={this.props.selected || NO_AUDIO} + options={this.state.audioList} + onChange={this.handleChange} + /> + ) + } +} + +const mapStateToProps = state => ({ + graph: state.graph, +}) + +export default connect(mapStateToProps)(AudioSelect) |
