2017-09-28 23:31:31 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2019-08-14 12:07:32 +10:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-10-25 04:45:08 +11:00
|
|
|
import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';
|
|
|
|
import { ReactComponent as EditIcon } from '@material-symbols/svg-600/outlined/edit.svg';
|
|
|
|
import { ReactComponent as InfoIcon } from '@material-symbols/svg-600/outlined/info.svg';
|
2023-05-24 01:15:17 +10:00
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
|
2023-05-09 11:11:56 +10:00
|
|
|
import { Icon } from 'mastodon/components/icon';
|
2017-09-28 23:31:31 +10:00
|
|
|
|
2023-05-24 01:15:17 +10:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
|
|
|
|
2019-08-14 12:07:32 +10:00
|
|
|
export default class Upload extends ImmutablePureComponent {
|
2017-09-28 23:31:31 +10:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
|
|
|
onUndo: PropTypes.func.isRequired,
|
2018-02-22 10:35:46 +11:00
|
|
|
onOpenFocalPoint: PropTypes.func.isRequired,
|
2017-09-28 23:31:31 +10:00
|
|
|
};
|
|
|
|
|
2018-10-25 03:17:15 +11:00
|
|
|
handleUndoClick = e => {
|
|
|
|
e.stopPropagation();
|
2017-09-28 23:31:31 +10:00
|
|
|
this.props.onUndo(this.props.media.get('id'));
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-09-28 23:31:31 +10:00
|
|
|
|
2018-10-25 03:17:15 +11:00
|
|
|
handleFocalPointClick = e => {
|
|
|
|
e.stopPropagation();
|
2018-02-22 10:35:46 +11:00
|
|
|
this.props.onOpenFocalPoint(this.props.media.get('id'));
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2018-02-22 10:35:46 +11:00
|
|
|
|
2017-09-28 23:31:31 +10:00
|
|
|
render () {
|
2022-11-12 07:22:17 +11:00
|
|
|
const { media } = this.props;
|
2023-02-11 08:03:35 +11:00
|
|
|
|
|
|
|
if (!media) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:35:46 +11:00
|
|
|
const focusX = media.getIn(['meta', 'focus', 'x']);
|
|
|
|
const focusY = media.getIn(['meta', 'focus', 'y']);
|
|
|
|
const x = ((focusX / 2) + .5) * 100;
|
|
|
|
const y = ((focusY / -2) + .5) * 100;
|
2017-09-28 23:31:31 +10:00
|
|
|
|
|
|
|
return (
|
2023-06-16 20:03:06 +10:00
|
|
|
<div className='compose-form__upload'>
|
2017-09-28 23:31:31 +10:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
|
|
|
|
{({ scale }) => (
|
2018-02-22 10:35:46 +11:00
|
|
|
<div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
2022-03-22 19:48:12 +11:00
|
|
|
<div className='compose-form__upload__actions'>
|
2023-10-25 04:45:08 +11:00
|
|
|
<button type='button' className='icon-button' onClick={this.handleUndoClick}><Icon id='times' icon={CloseIcon} /> <FormattedMessage id='upload_form.undo' defaultMessage='Delete' /></button>
|
|
|
|
<button type='button' className='icon-button' onClick={this.handleFocalPointClick}><Icon id='pencil' icon={EditIcon} /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>
|
2017-09-28 23:31:31 +10:00
|
|
|
</div>
|
2022-03-22 19:48:12 +11:00
|
|
|
|
2023-01-19 02:33:55 +11:00
|
|
|
{(media.get('description') || '').length === 0 && (
|
2022-03-22 19:48:12 +11:00
|
|
|
<div className='compose-form__upload__warning'>
|
2023-10-25 04:45:08 +11:00
|
|
|
<button type='button' className='icon-button' onClick={this.handleFocalPointClick}><Icon id='info-circle' icon={InfoIcon} /> <FormattedMessage id='upload_form.description_missing' defaultMessage='No description added' /></button>
|
2022-03-22 19:48:12 +11:00
|
|
|
</div>
|
|
|
|
)}
|
2017-09-28 23:31:31 +10:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|