Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

38483 - fix edit message draft reappearing #39027

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/pages/home/report/ReportActionItemMessageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ function ReportActionItemMessageEdit(
[reportID, action],
);

useEffect(() => () => debouncedSaveDraft.cancel(), [debouncedSaveDraft]);

/**
* Update frequently used emojis list. We debounce this method in the constructor so that UpdateFrequentlyUsedEmojis
* API is not called too often.
Expand Down Expand Up @@ -280,7 +282,6 @@ function ReportActionItemMessageEdit(
* Delete the draft of the comment being edited. This will take the comment out of "edit mode" with the old content.
*/
const deleteDraft = useCallback(() => {
debouncedSaveDraft.cancel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove the debouncedSaveDraft in the dependencies

Also, how about removing the cancel in the publishDraft at the same time? I think that's also stale.

// To prevent re-mount after user saves edit before debounce duration (example: within 1 second), we cancel
// debounce here.
debouncedSaveDraft.cancel();

Report.deleteReportActionDraft(reportID, action);

if (isActive()) {
Expand All @@ -295,7 +296,7 @@ function ReportActionItemMessageEdit(
keyboardDidHideListener.remove();
});
}
}, [action, debouncedSaveDraft, index, reportID, reportScrollManager, isActive]);
}, [action, index, reportID, reportScrollManager, isActive]);

/**
* Save the draft of the comment to be the new comment message. This will take the comment out of "edit mode" with
Expand All @@ -307,10 +308,6 @@ function ReportActionItemMessageEdit(
return;
}

// To prevent re-mount after user saves edit before debounce duration (example: within 1 second), we cancel
// debounce here.
debouncedSaveDraft.cancel();

const trimmedNewDraft = draft.trim();

// When user tries to save the empty message, it will delete it. Prompt the user to confirm deleting.
Expand All @@ -321,7 +318,7 @@ function ReportActionItemMessageEdit(
}
Report.editReportComment(reportID, action, trimmedNewDraft);
deleteDraft();
}, [action, debouncedSaveDraft, deleteDraft, draft, reportID]);
}, [action, deleteDraft, draft, reportID]);

/**
* @param emoji
Expand Down
Loading