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