Draft: Fix overwriting draft on chat change (#4485)

This commit is contained in:
Alexander Zinchuk 2024-04-19 13:38:47 +04:00
parent 956a59b457
commit 2688cd768a

View File

@ -1,4 +1,4 @@
import { useEffect, useRef } from '../../../../lib/teact/teact'; import { useEffect, useLayoutEffect, useRef } from '../../../../lib/teact/teact';
import { getActions } from '../../../../global'; import { getActions } from '../../../../global';
import type { ApiMessage } from '../../../../api/types'; import type { ApiMessage } from '../../../../api/types';
@ -73,10 +73,12 @@ const useDraft = ({
const html = getHtml(); const html = getHtml();
if (html) { if (html) {
saveDraft({ requestMeasure(() => {
chatId: prevState.chatId ?? chatId, saveDraft({
threadId: prevState.threadId ?? threadId, chatId: prevState.chatId ?? chatId,
text: parseHtmlAsFormattedText(html), threadId: prevState.threadId ?? threadId,
text: parseHtmlAsFormattedText(html),
});
}); });
} else { } else {
clearDraft({ clearDraft({
@ -117,8 +119,8 @@ const useDraft = ({
if (customEmojiIds.length) loadCustomEmojis({ ids: customEmojiIds }); if (customEmojiIds.length) loadCustomEmojis({ ids: customEmojiIds });
}, [chatId, threadId, draft, getHtml, setHtml, editedMessage, isDisabled]); }, [chatId, threadId, draft, getHtml, setHtml, editedMessage, isDisabled]);
// Save draft on chat change // Save draft on chat change. Should be layout effect to read correct html on cleanup
useEffect(() => { useLayoutEffect(() => {
if (isDisabled) { if (isDisabled) {
return undefined; return undefined;
} }