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