2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2016-11-14 03:08:52 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-17 01:20:52 +09:00
|
|
|
import IconButton from '../../../components/icon_button';
|
2016-11-18 23:36:16 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-03-24 11:50:30 +09:00
|
|
|
import UploadProgressContainer from '../containers/upload_progress_container';
|
|
|
|
import { Motion, spring } from 'react-motion';
|
2016-11-18 23:36:16 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
undo: { id: 'upload_form.undo', defaultMessage: 'Undo' }
|
|
|
|
});
|
2016-11-14 03:08:52 +09:00
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
class UploadForm extends React.PureComponent {
|
2016-11-14 03:08:52 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.list.isRequired,
|
|
|
|
onRemoveFile: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
2016-11-14 03:08:52 +09:00
|
|
|
render () {
|
2017-01-05 11:10:45 +09:00
|
|
|
const { intl, media } = this.props;
|
2016-11-17 01:20:52 +09:00
|
|
|
|
2017-03-24 11:50:30 +09:00
|
|
|
const uploads = media.map(attachment =>
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='compose-form__upload' key={attachment.get('id')}>
|
2017-03-24 11:50:30 +09:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
|
|
|
|
{({ scale }) =>
|
2017-04-29 21:29:13 +09:00
|
|
|
<div className='compose-form__upload-thumbnail' style={{ transform: `translateZ(0) scale(${scale})`, backgroundImage: `url(${attachment.get('preview_url')})` }}>
|
2017-03-24 11:50:30 +09:00
|
|
|
<IconButton icon='times' title={intl.formatMessage(messages.undo)} size={36} onClick={this.props.onRemoveFile.bind(this, attachment.get('id'))} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</Motion>
|
2016-11-14 03:08:52 +09:00
|
|
|
</div>
|
2017-03-24 11:50:30 +09:00
|
|
|
);
|
2016-11-14 03:08:52 +09:00
|
|
|
|
|
|
|
return (
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='compose-form__upload-wrapper'>
|
2017-03-24 11:50:30 +09:00
|
|
|
<UploadProgressContainer />
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='compose-form__uploads-wrapper'>{uploads}</div>
|
2016-11-14 03:08:52 +09:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
|
|
|
|
2016-11-17 01:20:52 +09:00
|
|
|
export default injectIntl(UploadForm);
|