2019-04-21 12:09:52 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2019-08-14 04:07:32 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
|
2023-11-15 12:01:51 +01:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2024-01-12 21:16:48 +01:00
|
|
|
import CloseIcon from 'mastodon/../material-icons/400-24px/close.svg?react';
|
|
|
|
import EditIcon from 'mastodon/../material-icons/400-24px/edit.svg?react';
|
|
|
|
import InfoIcon from 'mastodon/../material-icons/400-24px/info.svg?react';
|
|
|
|
|
2019-04-21 12:09:52 +02:00
|
|
|
|
2023-05-28 16:38:10 +02:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
|
|
|
|
2019-08-14 04:07:32 +02:00
|
|
|
export default class Upload extends ImmutablePureComponent {
|
2019-04-21 12:09:52 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
|
|
|
onUndo: PropTypes.func.isRequired,
|
|
|
|
onOpenFocalPoint: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleUndoClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.props.onUndo(this.props.media.get('id'));
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2019-04-21 12:09:52 +02:00
|
|
|
|
|
|
|
handleFocalPointClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.props.onOpenFocalPoint(this.props.media.get('id'));
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2019-04-21 12:09:52 +02:00
|
|
|
|
|
|
|
render () {
|
2022-11-11 21:22:17 +01:00
|
|
|
const { media } = this.props;
|
2023-02-10 22:03:35 +01:00
|
|
|
|
|
|
|
if (!media) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-21 12:09:52 +02: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;
|
|
|
|
|
|
|
|
return (
|
2023-06-16 12:03:06 +02:00
|
|
|
<div className='compose-form__upload'>
|
2023-02-03 20:52:07 +01:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
|
2019-04-21 12:09:52 +02:00
|
|
|
{({ scale }) => (
|
2022-11-06 13:30:37 +01:00
|
|
|
<div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
|
|
|
<div className='compose-form__upload__actions'>
|
2023-10-24 19:45:08 +02: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>
|
2019-04-21 12:09:52 +02:00
|
|
|
</div>
|
2022-03-22 09:48:12 +01:00
|
|
|
|
2023-01-18 16:33:55 +01:00
|
|
|
{(media.get('description') || '').length === 0 && (
|
2022-11-06 13:30:37 +01:00
|
|
|
<div className='compose-form__upload__warning'>
|
2023-10-24 19:45:08 +02: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 09:48:12 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2019-04-21 12:09:52 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|