2017-09-28 09:31:31 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 11:15:17 -04:00
|
|
|
|
2019-08-13 22:07:32 -04:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-23 11:15:17 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2023-05-23 11:15:17 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
|
|
|
import spring from 'react-motion/lib/spring';
|
|
|
|
|
2024-02-23 10:32:13 -05:00
|
|
|
import CloseIcon from '@/material-icons/400-20px/close.svg?react';
|
2024-01-16 05:27:26 -05:00
|
|
|
import EditIcon from '@/material-icons/400-24px/edit.svg?react';
|
2024-01-25 10:41:31 -05:00
|
|
|
import WarningIcon from '@/material-icons/400-24px/warning.svg?react';
|
|
|
|
import { Blurhash } from 'mastodon/components/blurhash';
|
2023-05-08 21:11:56 -04:00
|
|
|
import { Icon } from 'mastodon/components/icon';
|
2017-09-28 09:31:31 -04:00
|
|
|
|
2023-05-23 11:15:17 -04:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
|
|
|
|
2019-08-13 22:07:32 -04:00
|
|
|
export default class Upload extends ImmutablePureComponent {
|
2017-09-28 09:31:31 -04:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
2024-01-25 10:41:31 -05:00
|
|
|
sensitive: PropTypes.bool,
|
2017-09-28 09:31:31 -04:00
|
|
|
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'));
|
2023-01-29 19:45:35 -05:00
|
|
|
};
|
2017-09-28 09:31:31 -04:00
|
|
|
|
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'));
|
2023-01-29 19:45:35 -05:00
|
|
|
};
|
2018-02-21 18:35:46 -05:00
|
|
|
|
2017-09-28 09:31:31 -04:00
|
|
|
render () {
|
2024-01-25 10:41:31 -05:00
|
|
|
const { media, sensitive } = this.props;
|
2023-02-10 16:03:35 -05:00
|
|
|
|
|
|
|
if (!media) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
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;
|
2024-01-25 10:41:31 -05:00
|
|
|
const missingDescription = (media.get('description') || '').length === 0;
|
2017-09-28 09:31:31 -04:00
|
|
|
|
|
|
|
return (
|
2023-06-16 06:03:06 -04:00
|
|
|
<div className='compose-form__upload'>
|
2017-09-28 09:31:31 -04:00
|
|
|
<Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
|
|
|
|
{({ scale }) => (
|
2024-01-25 10:41:31 -05:00
|
|
|
<div className='compose-form__upload__thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: !sensitive ? `url(${media.get('preview_url')})` : null, backgroundPosition: `${x}% ${y}%` }}>
|
|
|
|
{sensitive && <Blurhash
|
|
|
|
hash={media.get('blurhash')}
|
|
|
|
className='compose-form__upload__preview'
|
|
|
|
/>}
|
|
|
|
|
2022-03-22 04:48:12 -04:00
|
|
|
<div className='compose-form__upload__actions'>
|
2024-01-25 10:41:31 -05:00
|
|
|
<button type='button' className='icon-button compose-form__upload__delete' onClick={this.handleUndoClick}><Icon icon={CloseIcon} /></button>
|
|
|
|
<button type='button' className='icon-button' onClick={this.handleFocalPointClick}><Icon icon={EditIcon} /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>
|
2017-09-28 09:31:31 -04:00
|
|
|
</div>
|
2022-03-22 04:48:12 -04:00
|
|
|
|
2024-01-25 10:41:31 -05:00
|
|
|
<div className='compose-form__upload__warning'>
|
|
|
|
<button type='button' className={classNames('icon-button', { active: missingDescription })} onClick={this.handleFocalPointClick}>{missingDescription && <Icon icon={WarningIcon} />} ALT</button>
|
|
|
|
</div>
|
2017-09-28 09:31:31 -04:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|