Mostly resolves #8, though attachments are still not displayed in public viewmaster
parent
1efa8e48d1
commit
499beb4484
After Width: | Height: | Size: 180 B |
@ -0,0 +1,37 @@ |
|||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
||||||
|
import Button from './button'; |
||||||
|
|
||||||
|
const UploadButton = React.createClass({ |
||||||
|
|
||||||
|
propTypes: { |
||||||
|
disabled: React.PropTypes.bool, |
||||||
|
onSelectFile: React.PropTypes.func.isRequired |
||||||
|
}, |
||||||
|
|
||||||
|
mixins: [PureRenderMixin], |
||||||
|
|
||||||
|
handleChange (e) { |
||||||
|
if (e.target.files.length > 0) { |
||||||
|
this.props.onSelectFile(e.target.files); |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
handleClick () { |
||||||
|
this.refs.fileElement.click(); |
||||||
|
}, |
||||||
|
|
||||||
|
render () { |
||||||
|
return ( |
||||||
|
<div> |
||||||
|
<Button disabled={this.props.disabled} onClick={this.handleClick} block={true}> |
||||||
|
<i className='fa fa-fw fa-photo' /> Add images |
||||||
|
</Button> |
||||||
|
|
||||||
|
<input ref='fileElement' type='file' onChange={this.handleChange} disabled={this.props.disabled} style={{ display: 'none' }} /> |
||||||
|
</div> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
export default UploadButton; |
@ -0,0 +1,41 @@ |
|||||||
|
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
||||||
|
import ImmutablePropTypes from 'react-immutable-proptypes'; |
||||||
|
import UploadButton from './upload_button'; |
||||||
|
import IconButton from './icon_button'; |
||||||
|
|
||||||
|
const UploadForm = React.createClass({ |
||||||
|
|
||||||
|
propTypes: { |
||||||
|
media: ImmutablePropTypes.list.isRequired, |
||||||
|
is_uploading: React.PropTypes.bool, |
||||||
|
onSelectFile: React.PropTypes.func.isRequired, |
||||||
|
onRemoveFile: React.PropTypes.func.isRequired |
||||||
|
}, |
||||||
|
|
||||||
|
mixins: [PureRenderMixin], |
||||||
|
|
||||||
|
render () { |
||||||
|
let uploads = this.props.media.map(function (attachment) { |
||||||
|
return ( |
||||||
|
<div key={attachment.get('id')} style={{ borderRadius: '4px', marginBottom: '10px' }} className='transparent-background'> |
||||||
|
<div style={{ width: '100%', height: '100px', borderRadius: '4px', background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }}> |
||||||
|
<IconButton icon='times' title='Undo' size={36} onClick={() => this.props.onRemoveFile(attachment.get('id'))} /> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
); |
||||||
|
}.bind(this)); |
||||||
|
|
||||||
|
return ( |
||||||
|
<div style={{ marginBottom: '20px', padding: '10px', paddingTop: '0' }}> |
||||||
|
<UploadButton onSelectFile={this.props.onSelectFile} disabled={this.props.is_uploading || this.props.media.size > 3} /> |
||||||
|
|
||||||
|
<div style={{ marginTop: '10px', overflow: 'hidden' }}> |
||||||
|
{uploads} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
export default UploadForm; |
@ -0,0 +1,25 @@ |
|||||||
|
import { connect } from 'react-redux'; |
||||||
|
import UploadForm from '../components/upload_form'; |
||||||
|
import { uploadCompose, undoUploadCompose } from '../actions/compose'; |
||||||
|
|
||||||
|
const mapStateToProps = function (state, props) { |
||||||
|
return { |
||||||
|
media: state.getIn(['compose', 'media_attachments']), |
||||||
|
progress: state.getIn(['compose', 'progress']), |
||||||
|
is_uploading: state.getIn(['compose', 'is_uploading']) |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
const mapDispatchToProps = function (dispatch) { |
||||||
|
return { |
||||||
|
onSelectFile: function (files) { |
||||||
|
dispatch(uploadCompose(files)); |
||||||
|
}, |
||||||
|
|
||||||
|
onRemoveFile: function (media_id) { |
||||||
|
dispatch(undoUploadCompose(media_id)); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(UploadForm); |
@ -1,3 +1,4 @@ |
|||||||
object @media |
object @media |
||||||
attribute :id |
attribute :id |
||||||
node(:url) { |media| full_asset_url(media.file.url) } |
node(:url) { |media| full_asset_url(media.file.url) } |
||||||
|
node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } |
||||||
|
Loading…
Reference in new issue