Skip to content

Commit

Permalink
runfix: Reset complete draft state when sending message (#15950)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Oct 9, 2023
1 parent 338ecfd commit 61188dc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
29 changes: 14 additions & 15 deletions src/script/components/InputBar/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ export const InputBar = ({
),
});

const resetDraftState = (resetInputValue = false) => {
if (resetInputValue) {
editorRef.current?.update(() => {
$getRoot().clear();
});
}
const resetDraftState = () => {
setReplyMessageEntity(null);
editorRef.current?.update(() => {
$getRoot().clear();
});
};

const clearPastedFile = () => setPastedFile(null);
Expand Down Expand Up @@ -237,12 +236,12 @@ export const InputBar = ({
};
});

const cancelMessageEditing = (resetDraft = true, resetInputValue = false) => {
const cancelMessageEditing = (resetDraft = true) => {
setEditedMessage(undefined);
setReplyMessageEntity(null);

if (resetDraft) {
resetDraftState(resetInputValue);
resetDraftState();
}
};

Expand All @@ -253,7 +252,7 @@ export const InputBar = ({
const editMessage = (messageEntity?: ContentMessage) => {
if (messageEntity?.isEditable() && messageEntity !== editedMessage) {
cancelMessageReply();
cancelMessageEditing(true, true);
cancelMessageEditing(true);
setEditedMessage(messageEntity);

if (messageEntity.quote() && conversation) {
Expand Down Expand Up @@ -291,7 +290,7 @@ export const InputBar = ({

const sendMessageEdit = (messageText: string, mentions: MentionEntity[]): void | Promise<any> => {
const mentionEntities = mentions.slice(0);
cancelMessageEditing(true, true);
cancelMessageEditing(true);

if (!messageText.length && editedMessage) {
return messageRepository.deleteMessageForEveryone(conversation, editedMessage);
Expand Down Expand Up @@ -345,7 +344,7 @@ export const InputBar = ({
}

editorRef.current?.focus();
editorRef.current?.update(() => $getRoot().clear());
resetDraftState();
};

const onGifClick = () => openGiphy(textValue);
Expand Down Expand Up @@ -403,13 +402,13 @@ export const InputBar = ({
const sendGiphy = (gifUrl: string, tag: string): void => {
void generateQuote().then(quoteEntity => {
void messageRepository.sendGif(conversation, gifUrl, tag, quoteEntity);
cancelMessageEditing(true, true);
cancelMessageEditing(true);
});
};

const onWindowClick = (event: Event): void =>
handleClickOutsideOfInputBar(event, () => {
cancelMessageEditing(true, true);
cancelMessageEditing(true);
cancelMessageReply();
});

Expand Down Expand Up @@ -506,7 +505,7 @@ export const InputBar = ({
input: textValue,
isEditing: isEditing,
isScaledDown: isScaledDown,
onCancelEditing: () => cancelMessageEditing(true, true),
onCancelEditing: () => cancelMessageEditing(true),
onClickPing: onPingClick,
onGifClick: onGifClick,
onSelectFiles: uploadFiles,
Expand Down Expand Up @@ -551,7 +550,7 @@ export const InputBar = ({
editedMessage={editedMessage}
onEscape={() => {
if (editedMessage) {
cancelMessageEditing(true, true);
cancelMessageEditing(true);
} else if (replyMessageEntity) {
cancelMessageReply();
}
Expand Down
3 changes: 1 addition & 2 deletions src/script/components/InputBar/util/DraftStateUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ export const saveDraftState = async (
replyMessageId?: string,
): Promise<void> => {
// we only save state for newly written messages
const storeReply = replyMessageId;
const storageKey = generateConversationInputStorageKey(conversationEntity);

await storageRepository.storageService.saveToSimpleStorage<any>(storageKey, {
editorState,
replyId: storeReply,
replyId: replyMessageId,
});
};

Expand Down
5 changes: 4 additions & 1 deletion src/script/components/RichTextEditor/RichTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ export const RichTextEditor = ({

function Placeholder({text, hasLocalEphemeralTimer}: {text: string; hasLocalEphemeralTimer: boolean}) {
return (
<div className={cx('editor-placeholder', {'conversation-input-bar-text--accent': hasLocalEphemeralTimer})}>
<div
className={cx('editor-placeholder', {'conversation-input-bar-text--accent': hasLocalEphemeralTimer})}
data-uie-name="input-placeholder"
>
{text}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/script/components/RichTextEditor/nodes/Mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const Mention = (props: MentionComponentProps) => {
}, [editor, moveCursor, selectMention, unselectMention, deleteMention]);

return (
<span ref={ref} className={classNameFinal} data-mention={mention}>
<span ref={ref} className={classNameFinal} data-mention={mention} data-uie-name="item-input-mention">
{mention}
</span>
);
Expand Down

0 comments on commit 61188dc

Please sign in to comment.