Skip to content

Commit

Permalink
Update drafts when removing attachments in forward modal
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebuilds-signal committed Apr 25, 2023
1 parent 406916e commit 1eddf25
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ts/components/ForwardMessagesModal.tsx
Expand Up @@ -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}
Expand Down Expand Up @@ -437,6 +440,7 @@ type ForwardMessageEditorProps = Readonly<{
bodyRanges: HydratedBodyRangesType,
caretLocation?: number
) => unknown;
onChangeAttachments: (attachments: ReadonlyArray<AttachmentType>) => unknown;
onSubmit: () => unknown;
theme: ThemeType;
i18n: LocalizerType;
Expand All @@ -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 ? (
Expand All @@ -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}
Expand Down

0 comments on commit 1eddf25

Please sign in to comment.