Reorders useEffect so that draft content is retained
This commit is contained in:
parent
4455328312
commit
3ec235bc56
1 changed files with 14 additions and 14 deletions
|
@ -483,20 +483,6 @@ export function CompositionArea({
|
||||||
[inputApiRef, onPickEmoji]
|
[inputApiRef, onPickEmoji]
|
||||||
);
|
);
|
||||||
|
|
||||||
const previousConversationId = usePrevious(conversationId, conversationId);
|
|
||||||
useEffect(() => {
|
|
||||||
if (conversationId === previousConversationId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!draftText) {
|
|
||||||
inputApiRef.current?.setContents('');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
inputApiRef.current?.setContents(draftText, draftBodyRanges, true);
|
|
||||||
}, [conversationId, draftBodyRanges, draftText, previousConversationId]);
|
|
||||||
|
|
||||||
// We want to reset the state of Quill only if:
|
// We want to reset the state of Quill only if:
|
||||||
//
|
//
|
||||||
// - Our other device edits the message (edit history length would change)
|
// - Our other device edits the message (edit history length would change)
|
||||||
|
@ -520,6 +506,20 @@ export function CompositionArea({
|
||||||
);
|
);
|
||||||
}, [draftBodyRanges, draftEditMessageBody, hasEditDraftChanged]);
|
}, [draftBodyRanges, draftEditMessageBody, hasEditDraftChanged]);
|
||||||
|
|
||||||
|
const previousConversationId = usePrevious(conversationId, conversationId);
|
||||||
|
useEffect(() => {
|
||||||
|
if (conversationId === previousConversationId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!draftText) {
|
||||||
|
inputApiRef.current?.setContents('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inputApiRef.current?.setContents(draftText, draftBodyRanges, true);
|
||||||
|
}, [conversationId, draftBodyRanges, draftText, previousConversationId]);
|
||||||
|
|
||||||
const handleToggleLarge = useCallback(() => {
|
const handleToggleLarge = useCallback(() => {
|
||||||
setLarge(l => !l);
|
setLarge(l => !l);
|
||||||
}, [setLarge]);
|
}, [setLarge]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue