Update drafts when removing attachments in forward modal

This commit is contained in:
Jamie Kyle 2023-04-25 14:54:59 -07:00 committed by GitHub
parent 406916ea42
commit 1eddf252e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -318,6 +318,9 @@ export function ForwardMessagesModal({
onChange={(messageBody, bodyRanges) => { onChange={(messageBody, bodyRanges) => {
onChange([{ ...lonelyDraft, messageBody, bodyRanges }]); onChange([{ ...lonelyDraft, messageBody, bodyRanges }]);
}} }}
onChangeAttachments={attachments => {
onChange([{ ...lonelyDraft, attachments }]);
}}
removeLinkPreview={removeLinkPreview} removeLinkPreview={removeLinkPreview}
theme={theme} theme={theme}
i18n={i18n} i18n={i18n}
@ -437,6 +440,7 @@ type ForwardMessageEditorProps = Readonly<{
bodyRanges: HydratedBodyRangesType, bodyRanges: HydratedBodyRangesType,
caretLocation?: number caretLocation?: number
) => unknown; ) => unknown;
onChangeAttachments: (attachments: ReadonlyArray<AttachmentType>) => unknown;
onSubmit: () => unknown; onSubmit: () => unknown;
theme: ThemeType; theme: ThemeType;
i18n: LocalizerType; i18n: LocalizerType;
@ -449,13 +453,11 @@ function ForwardMessageEditor({
RenderCompositionTextArea, RenderCompositionTextArea,
removeLinkPreview, removeLinkPreview,
onChange, onChange,
onChangeAttachments,
onSubmit, onSubmit,
theme, theme,
}: ForwardMessageEditorProps): JSX.Element { }: ForwardMessageEditorProps): JSX.Element {
const [attachmentsToForward, setAttachmentsToForward] = useState< const { attachments } = draft;
ReadonlyArray<AttachmentType>
>(draft.attachments ?? []);
return ( return (
<div className="module-ForwardMessageModal__main-body"> <div className="module-ForwardMessageModal__main-body">
{linkPreview ? ( {linkPreview ? (
@ -472,15 +474,15 @@ function ForwardMessageEditor({
/> />
</div> </div>
) : null} ) : null}
{attachmentsToForward && attachmentsToForward.length ? ( {attachments != null && attachments.length > 0 ? (
<AttachmentList <AttachmentList
attachments={attachmentsToForward} attachments={attachments}
i18n={i18n} i18n={i18n}
onCloseAttachment={(attachment: AttachmentType) => { onCloseAttachment={(attachment: AttachmentType) => {
const newAttachments = attachmentsToForward.filter( const newAttachments = attachments.filter(
currentAttachment => currentAttachment !== attachment currentAttachment => currentAttachment !== attachment
); );
setAttachmentsToForward(newAttachments); onChangeAttachments(newAttachments);
}} }}
/> />
) : null} ) : null}