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
|
|
|
|
2024-01-25 16:41:31 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
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';
|
|
|
|
|
2024-02-23 16:32:13 +01:00
|
|
|
import CloseIcon from '@/material-icons/400-20px/close.svg?react';
|
2024-01-16 11:27:26 +01:00
|
|
|
import EditIcon from '@/material-icons/400-24px/edit.svg?react';
|
2024-01-25 16:41:31 +01:00
|
|
|
import WarningIcon from '@/material-icons/400-24px/warning.svg?react';
|
|
|
|
import { Blurhash } from 'flavours/glitch/components/blurhash';
|
2023-11-15 12:01:51 +01:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2024-01-12 21:16:48 +01: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,
|
2024-01-25 16:41:31 +01:00
|
|
|
sensitive: PropTypes.bool,
|
2019-04-21 12:09:52 +02:00
|
|
|
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 () {
|
2024-01-25 16:41:31 +01:00
|
|
|
const { media, sensitive } = 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;
|
2024-01-25 16:41:31 +01:00
|
|
|
const missingDescription = (media.get('description') || '').length === 0;
|
2019-04-21 12:09:52 +02:00
|
|
|
|
|
|
|
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 }) => (
|
2024-01-25 16:41:31 +01: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-11-06 13:30:37 +01:00
|
|
|
<div className='compose-form__upload__actions'>
|
2024-01-25 16:41:31 +01: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>
|
2019-04-21 12:09:52 +02:00
|
|
|
</div>
|
2022-03-22 09:48:12 +01:00
|
|
|
|
2024-01-25 16:41:31 +01: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>
|
2019-04-21 12:09:52 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|