import PropTypes from 'prop-types'; import { useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import { useDispatch, useSelector } from 'react-redux'; import spring from 'react-motion/lib/spring'; import CloseIcon from '@/material-icons/400-20px/close.svg?react'; import EditIcon from '@/material-icons/400-24px/edit.svg?react'; import WarningIcon from '@/material-icons/400-24px/warning.svg?react'; import { undoUploadCompose, initMediaEditModal } from 'mastodon/actions/compose'; import { Blurhash } from 'mastodon/components/blurhash'; import { Icon } from 'mastodon/components/icon'; import Motion from 'mastodon/features/ui/util/optional_motion'; export const Upload = ({ id, onDragStart, onDragEnter, onDragEnd }) => { const dispatch = useDispatch(); const media = useSelector(state => state.getIn(['compose', 'media_attachments']).find(item => item.get('id') === id)); const sensitive = useSelector(state => state.getIn(['compose', 'spoiler'])); const handleUndoClick = useCallback(() => { dispatch(undoUploadCompose(id)); }, [dispatch, id]); const handleFocalPointClick = useCallback(() => { dispatch(initMediaEditModal(id)); }, [dispatch, id]); const handleDragStart = useCallback(() => { onDragStart(id); }, [onDragStart, id]); const handleDragEnter = useCallback(() => { onDragEnter(id); }, [onDragEnter, id]); if (!media) { return null; } 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; const missingDescription = (media.get('description') || '').length === 0; return (
{({ scale }) => (
{sensitive && }
)}
); }; Upload.propTypes = { id: PropTypes.string, onDragEnter: PropTypes.func, onDragStart: PropTypes.func, onDragEnd: PropTypes.func, };