2017-05-03 03:04:16 +03:00
|
|
|
import React from 'react';
|
2016-11-13 20:08:52 +02:00
|
|
|
import IconButton from '../../../components/icon_button';
|
2017-04-21 21:05:35 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-18 16:36:16 +02:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-05-08 17:49:53 +03:00
|
|
|
import { connect } from 'react-redux';
|
2017-05-28 20:15:35 +03:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-11-18 16:36:16 +02:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-06-26 01:14:29 +03:00
|
|
|
upload: { id: 'upload_button.label', defaultMessage: 'Add images, a video or an audio file' },
|
2016-11-18 16:36:16 +02:00
|
|
|
});
|
2016-09-07 19:17:15 +03:00
|
|
|
|
2017-05-08 17:49:53 +03:00
|
|
|
const makeMapStateToProps = () => {
|
2017-06-23 17:05:04 +03:00
|
|
|
const mapStateToProps = state => ({
|
2017-05-28 20:15:35 +03:00
|
|
|
acceptContentTypes: state.getIn(['media_attachments', 'accept_content_types']),
|
2017-05-08 17:49:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
2017-05-20 18:31:47 +03:00
|
|
|
};
|
2017-04-23 15:18:58 +03:00
|
|
|
|
|
|
|
const iconStyle = {
|
|
|
|
height: null,
|
2017-05-20 18:31:47 +03:00
|
|
|
lineHeight: '27px',
|
|
|
|
};
|
2017-04-23 15:18:58 +03:00
|
|
|
|
2018-09-14 18:59:48 +03:00
|
|
|
export default @connect(makeMapStateToProps)
|
2017-06-23 20:36:54 +03:00
|
|
|
@injectIntl
|
2018-09-14 18:59:48 +03:00
|
|
|
class UploadButton extends ImmutablePureComponent {
|
2016-09-07 19:17:15 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
|
|
|
disabled: PropTypes.bool,
|
2019-03-06 05:53:37 +02:00
|
|
|
unavailable: PropTypes.bool,
|
2017-05-12 15:44:10 +03:00
|
|
|
onSelectFile: PropTypes.func.isRequired,
|
|
|
|
style: PropTypes.object,
|
|
|
|
resetFileKey: PropTypes.number,
|
2017-05-28 20:15:35 +03:00
|
|
|
acceptContentTypes: ImmutablePropTypes.listOf(PropTypes.string).isRequired,
|
2017-05-20 18:31:47 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
2016-09-07 19:17:15 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
handleChange = (e) => {
|
2016-09-07 19:17:15 +03:00
|
|
|
if (e.target.files.length > 0) {
|
|
|
|
this.props.onSelectFile(e.target.files);
|
|
|
|
}
|
2023-01-30 02:45:35 +02:00
|
|
|
};
|
2016-09-07 19:17:15 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
handleClick = () => {
|
2016-11-13 20:08:52 +02:00
|
|
|
this.fileElement.click();
|
2023-01-30 02:45:35 +02:00
|
|
|
};
|
2016-11-13 20:08:52 +02:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
setRef = (c) => {
|
2016-11-13 20:08:52 +02:00
|
|
|
this.fileElement = c;
|
2023-01-30 02:45:35 +02:00
|
|
|
};
|
2016-09-07 19:17:15 +03:00
|
|
|
|
|
|
|
render () {
|
2019-03-06 05:53:37 +02:00
|
|
|
const { intl, resetFileKey, unavailable, disabled, acceptContentTypes } = this.props;
|
2017-04-23 15:18:58 +03:00
|
|
|
|
2019-03-06 05:53:37 +02:00
|
|
|
if (unavailable) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-11-16 18:20:52 +02:00
|
|
|
|
2020-06-26 01:14:29 +03:00
|
|
|
const message = intl.formatMessage(messages.upload);
|
|
|
|
|
2016-09-07 19:17:15 +03:00
|
|
|
return (
|
2017-04-23 05:26:55 +03:00
|
|
|
<div className='compose-form__upload-button'>
|
2020-06-26 01:14:29 +03:00
|
|
|
<IconButton icon='paperclip' title={message} disabled={disabled} onClick={this.handleClick} className='compose-form__upload-button-icon' size={18} inverted style={iconStyle} />
|
2017-07-28 01:54:48 +03:00
|
|
|
<label>
|
2020-06-26 01:14:29 +03:00
|
|
|
<span style={{ display: 'none' }}>{message}</span>
|
2017-07-28 01:54:48 +03:00
|
|
|
<input
|
|
|
|
key={resetFileKey}
|
|
|
|
ref={this.setRef}
|
|
|
|
type='file'
|
2019-02-02 21:22:05 +02:00
|
|
|
multiple
|
2017-07-28 01:54:48 +03:00
|
|
|
accept={acceptContentTypes.toArray().join(',')}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
disabled={disabled}
|
|
|
|
style={{ display: 'none' }}
|
|
|
|
/>
|
|
|
|
</label>
|
2016-09-07 19:17:15 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|