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