2017-09-28 09:31:31 -04:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-10-16 03:36:15 -04:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
2017-09-28 09:31:31 -04:00
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-08-13 22:07:32 -04:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-09-28 09:31:31 -04:00
|
|
|
import classNames from 'classnames';
|
2019-01-31 18:14:05 -05:00
|
|
|
import Icon from 'mastodon/components/icon';
|
2017-09-28 09:31:31 -04:00
|
|
|
|
2019-08-13 22:07:32 -04:00
|
|
|
export default class Upload extends ImmutablePureComponent {
|
2017-09-28 09:31:31 -04:00
|
|
|
|
2018-10-10 19:31:03 -04:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2017-09-28 09:31:31 -04:00
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
|
|
|
onUndo: PropTypes.func.isRequired,
|
2018-02-21 18:35:46 -05:00
|
|
|
onOpenFocalPoint: PropTypes.func.isRequired,
|
2017-09-28 09:31:31 -04:00
|
|
|
};
|
|
|
|
|
2018-10-24 12:17:15 -04:00
|
|
|
handleUndoClick = e => {
|
|
|
|
e.stopPropagation();
|
2017-09-28 09:31:31 -04:00
|
|
|
this.props.onUndo(this.props.media.get('id'));
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:17:15 -04:00
|
|
|
handleFocalPointClick = e => {
|
|
|
|
e.stopPropagation();
|
2018-02-21 18:35:46 -05:00
|
|
|
this.props.onOpenFocalPoint(this.props.media.get('id'));
|
|
|
|
}
|
|
|
|
|
2017-09-28 09:31:31 -04:00
|
|
|
render () {
|
2019-08-13 22:07:32 -04:00
|
|
|
const { media } = this.props;
|
2018-02-21 18:35:46 -05: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 09:31:31 -04:00
|
|
|
|
|
|
|
return (
|
2019-08-13 22:07:32 -04:00
|
|
|
<div className='compose-form__upload' tabIndex='0' role='button'>
|
2017-09-28 09:31:31 -04:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
|
|
|
|
{({ scale }) => (
|
2018-02-21 18:35:46 -05:00
|
|
|
<div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
2019-08-13 22:07:32 -04:00
|
|
|
<div className={classNames('compose-form__upload__actions', { active: true })}>
|
2019-01-31 18:14:05 -05:00
|
|
|
<button className='icon-button' onClick={this.handleUndoClick}><Icon id='times' /> <FormattedMessage id='upload_form.undo' defaultMessage='Delete' /></button>
|
2019-08-13 22:07:32 -04:00
|
|
|
<button className='icon-button' onClick={this.handleFocalPointClick}><Icon id='pencil' /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>
|
2017-09-28 09:31:31 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|