diff --git a/packages/pl-fe/src/actions/compose.ts b/packages/pl-fe/src/actions/compose.ts index 56353b9a8..f34561cf8 100644 --- a/packages/pl-fe/src/actions/compose.ts +++ b/packages/pl-fe/src/actions/compose.ts @@ -529,11 +529,11 @@ const uploadComposeFail = (composeId: string, error: unknown) => ({ const changeUploadCompose = (composeId: string, mediaId: string, params: Record) => (dispatch: AppDispatch, getState: () => RootState) => { - if (!isLoggedIn(getState)) return; + if (!isLoggedIn(getState)) return Promise.resolve(); dispatch(changeUploadComposeRequest(composeId)); - dispatch(updateMedia(mediaId, params)).then(response => { + return dispatch(updateMedia(mediaId, params)).then(response => { dispatch(changeUploadComposeSuccess(composeId, response)); }).catch(error => { dispatch(changeUploadComposeFail(composeId, mediaId, error)); diff --git a/packages/pl-fe/src/components/ui/textarea.tsx b/packages/pl-fe/src/components/ui/textarea.tsx index 8c3e758e1..c279f0f44 100644 --- a/packages/pl-fe/src/components/ui/textarea.tsx +++ b/packages/pl-fe/src/components/ui/textarea.tsx @@ -8,7 +8,7 @@ import { getTextDirection } from 'pl-fe/utils/rtl'; import Stack from './stack'; import Text from './text'; -interface ITextarea extends Pick, 'id' | 'maxLength' | 'onChange' | 'onClick' | 'onKeyDown' | 'onPaste' | 'required' | 'disabled' | 'rows' | 'readOnly'> { +interface ITextarea extends Pick, 'className' | 'id' | 'lang' | 'maxLength' | 'onChange' | 'onClick' | 'onKeyDown' | 'onKeyUp' | 'onPaste' | 'required' | 'disabled' | 'rows' | 'readOnly'> { /** Put the cursor into the input on mount. */ autoFocus?: boolean; /** Allows the textarea height to grow while typing */ @@ -52,6 +52,7 @@ const Textarea = React.forwardRef(({ theme = 'default', maxLength, value, + className, ...props }: ITextarea, ref: React.ForwardedRef) => { const length = value?.length || 0; @@ -98,7 +99,7 @@ const Textarea = React.forwardRef(({ 'font-mono': isCodeEditor, 'text-red-600 border-red-600': hasError, 'resize-none': !isResizeable, - })} + }, className)} dir={value?.length ? getTextDirection(value, { fallback: direction }) : undefined} /> diff --git a/packages/pl-fe/src/components/upload.tsx b/packages/pl-fe/src/components/upload.tsx index 24863058a..0e0c88113 100644 --- a/packages/pl-fe/src/components/upload.tsx +++ b/packages/pl-fe/src/components/upload.tsx @@ -4,11 +4,12 @@ import fileSpreadsheetIcon from '@tabler/icons/outline/file-spreadsheet.svg'; import fileTextIcon from '@tabler/icons/outline/file-text.svg'; import fileZipIcon from '@tabler/icons/outline/file-zip.svg'; import defaultIcon from '@tabler/icons/outline/paperclip.svg'; +import editIcon from '@tabler/icons/outline/pencil.svg'; import presentationIcon from '@tabler/icons/outline/presentation.svg'; import xIcon from '@tabler/icons/outline/x.svg'; import zoomInIcon from '@tabler/icons/outline/zoom-in.svg'; import clsx from 'clsx'; -import React, { useState } from 'react'; +import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { spring } from 'react-motion'; @@ -67,14 +68,13 @@ interface IUpload extends Pick, 'onDragStar media: MediaAttachment; onSubmit?(): void; onDelete?(): void; - onDescriptionChange?(description: string): void; + onDescriptionChange?(description: string): Promise; descriptionLimit?: number; withPreview?: boolean; } const Upload: React.FC = ({ media, - onSubmit, onDelete, onDescriptionChange, onDragStart, @@ -86,17 +86,6 @@ const Upload: React.FC = ({ const intl = useIntl(); const { openModal } = useModalsStore(); - const [hovered, setHovered] = useState(false); - const [focused, setFocused] = useState(false); - const [dirtyDescription, setDirtyDescription] = useState(null); - - const handleKeyDown: React.KeyboardEventHandler = (e) => { - if (onSubmit && e.keyCode === 13 && (e.ctrlKey || e.metaKey)) { - handleInputBlur(); - onSubmit(); - } - }; - const handleUndoClick: React.MouseEventHandler = e => { if (onDelete) { e.stopPropagation(); @@ -104,41 +93,25 @@ const Upload: React.FC = ({ } }; - const handleInputChange: React.ChangeEventHandler = e => { - setDirtyDescription(e.target.value); - }; - - const handleMouseEnter = () => { - setHovered(true); - }; - - const handleMouseLeave = () => { - setHovered(false); - }; - - const handleInputFocus = () => { - setFocused(true); - }; - - const handleClick = () => { - setFocused(true); - }; - - const handleInputBlur = () => { - setFocused(false); - setDirtyDescription(null); - - if (dirtyDescription !== null && onDescriptionChange) { - onDescriptionChange(dirtyDescription); - } - }; - const handleOpenModal = () => { openModal('MEDIA', { media: [media], index: 0 }); }; - const active = hovered || focused; - const description = dirtyDescription || (dirtyDescription !== '' && media.description) || ''; + const handleOpenAltTextModal = (e: React.MouseEvent) => { + e.stopPropagation(); + e.preventDefault(); + + if (!onDescriptionChange) return; + + openModal('ALT_TEXT', { + media, + previousDescription: media.description, + descriptionLimit: descriptionLimit!, + onSubmit: (newDescription: string) => onDescriptionChange(newDescription), + }); + }; + + const description = media.description; const focusX = media.type === 'image' && media.meta?.focus?.x || undefined; const focusY = media.type === 'image' && media.meta?.focus?.y || undefined; const x = focusX ? ((focusX / 2) + .5) * 100 : undefined; @@ -157,9 +130,6 @@ const Upload: React.FC = ({
= ({ }} > + {onDescriptionChange && ( + + )} {(withPreview && mediaType !== 'unknown' && Boolean(media.url)) && ( = ({ )} - {onDescriptionChange && ( -
-