Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget-chat): Add file upload API calls
- Loading branch information
Bernie Zang
committed
Nov 16, 2016
1 parent
8e5386b
commit c523442
Showing
11 changed files
with
256 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
75 changes: 75 additions & 0 deletions
75
packages/widget-chat/src/containers/file-uploader/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {bindActionCreators} from 'redux'; | ||
import classNames from 'classnames'; | ||
|
||
import spark from '../../modules/redux-spark/spark'; | ||
import {constructFile} from '../../utils/files'; | ||
import {addShareFiles} from '../../actions/activity'; | ||
|
||
import AddFileButton from '../../components/add-file-button'; | ||
import styles from './styles.css'; | ||
|
||
export class FileUploader extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.handleFileChange = this.handleFileChange.bind(this); | ||
} | ||
|
||
getFiles() { | ||
const props = this.props; | ||
return props.activity.files; | ||
} | ||
|
||
handleFileChange(e) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
const props = this.props; | ||
|
||
const { | ||
activity, | ||
conversation | ||
} = props; | ||
|
||
const files = []; | ||
|
||
for (let i = 0; i < e.target.files.length; i++) { | ||
files.push(constructFile(e.target.files[i])); | ||
} | ||
props.addShareFiles(conversation, activity, files, spark); | ||
|
||
// Clear the value of the input so the same file can be added again. | ||
e.target.value = ``; | ||
} | ||
|
||
uploadFiles(files) { | ||
return files; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={classNames(`file-uploader-container`, styles.container)}> | ||
<div className={classNames(`add-file-container`, styles.addFileContainer)}> | ||
<AddFileButton onChange={this.handleFileChange} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FileUploader.propTypes = { | ||
handleSubmit: PropTypes.func | ||
}; | ||
|
||
|
||
export default connect( | ||
(state) => ({ | ||
activity: state.activity.activity, | ||
conversation: state.conversation | ||
}), | ||
(dispatch) => bindActionCreators({ | ||
addShareFiles | ||
}, dispatch) | ||
)(FileUploader); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters