2019-04-21 03:09:52 -07:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Motion from 'flavours/glitch/util/optional_motion';
|
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-08-13 19:07:32 -07:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2019-04-21 03:09:52 -07:00
|
|
|
import Icon from 'flavours/glitch/components/icon';
|
|
|
|
import { isUserTouching } from 'flavours/glitch/util/is_mobile';
|
|
|
|
|
2019-08-13 19:07:32 -07:00
|
|
|
export default class Upload extends ImmutablePureComponent {
|
2019-04-21 03:09:52 -07:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
|
|
|
onUndo: PropTypes.func.isRequired,
|
|
|
|
onOpenFocalPoint: PropTypes.func.isRequired,
|
2022-02-12 10:00:33 -08:00
|
|
|
isEditingStatus: PropTypes.func.isRequired,
|
2019-04-21 03:09:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
handleUndoClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.props.onUndo(this.props.media.get('id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFocalPointClick = e => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.props.onOpenFocalPoint(this.props.media.get('id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2022-02-12 10:00:33 -08:00
|
|
|
const { intl, media, isEditingStatus } = this.props;
|
2019-04-21 03:09:52 -07: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 (
|
2019-08-13 19:07:32 -07:00
|
|
|
<div className='composer--upload_form--item' tabIndex='0' role='button'>
|
2019-04-21 03:09:52 -07:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12, }) }}>
|
|
|
|
{({ scale }) => (
|
|
|
|
<div style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
2022-03-22 01:48:12 -07:00
|
|
|
<div className='composer--upload_form--actions'>
|
2019-09-09 06:28:45 -07:00
|
|
|
<button className='icon-button' onClick={this.handleUndoClick}><Icon id='times' /> <FormattedMessage id='upload_form.undo' defaultMessage='Delete' /></button>
|
2022-02-12 10:00:33 -08:00
|
|
|
{!isEditingStatus && (<button className='icon-button' onClick={this.handleFocalPointClick}><Icon id='pencil' /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>)}
|
2019-04-21 03:09:52 -07:00
|
|
|
</div>
|
2022-03-22 01:48:12 -07:00
|
|
|
|
|
|
|
{(media.get('description') || '').length === 0 && (
|
|
|
|
<div className='composer--upload_form--item__warning'>
|
|
|
|
<button className='icon-button' onClick={this.handleFocalPointClick}><Icon id='info-circle' /> <FormattedMessage id='upload_form.description_missing' defaultMessage='No description added' /></button>
|
|
|
|
</div>
|
|
|
|
)}
|
2019-04-21 03:09:52 -07:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|