Skip to content

Commit

Permalink
Merge pull request #25724 from Expensify/andrew-revert-24544
Browse files Browse the repository at this point in the history
Revert "Merge pull request #24544 from eh2077/21527-fix-sync-draft-and-edit-status-of-thread-first-chat"
  • Loading branch information
AndrewGable authored Aug 22, 2023
2 parents 51d55de + dbace82 commit df09b28
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,11 @@ function editReportComment(reportID, originalReportAction, textForNewComment) {
* Saves the draft for a comment report action. This will put the comment into "edit mode"
*
* @param {String} reportID
* @param {Object} reportAction
* @param {Number} reportActionID
* @param {String} draftMessage
*/
function saveReportActionDraft(reportID, reportAction, draftMessage) {
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${reportAction.reportActionID}`, draftMessage);
function saveReportActionDraft(reportID, reportActionID, draftMessage) {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${reportID}_${reportActionID}`, draftMessage);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export default [
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) =>
type === CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && !isArchivedRoom && !isChronosReport,
onPress: (closePopover, {reportID, reportAction, draftMessage}) => {
const editAction = () => Report.saveReportActionDraft(reportID, reportAction, _.isEmpty(draftMessage) ? getActionText(reportAction) : '');
const editAction = () => Report.saveReportActionDraft(reportID, reportAction.reportActionID, _.isEmpty(draftMessage) ? getActionText(reportAction) : '');

if (closePopover) {
// Hide popover, then call editAction
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ function ReportActionCompose({
const lastReportAction = _.find([...reportActions, parentReportAction], (action) => ReportUtils.canEditReportAction(action));

if (lastReportAction !== -1 && lastReportAction) {
Report.saveReportActionDraft(reportID, lastReportAction, _.last(lastReportAction.message).html);
Report.saveReportActionDraft(reportID, lastReportAction.reportActionID, _.last(lastReportAction.message).html);
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,7 @@ export default compose(
withReportActionsDrafts({
propName: 'draftMessage',
transformValue: (drafts, props) => {
const originalReportID = ReportUtils.getOriginalReportID(props.report.reportID, props.action);
const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${props.action.reportActionID}`;
const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${props.report.reportID}_${props.action.reportActionID}`;
return lodashGet(drafts, draftKey, '');
},
}),
Expand Down
15 changes: 4 additions & 11 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ function ReportActionItemMessageEdit(props) {
const isFocusedRef = useRef(false);
const insertedEmojis = useRef([]);

useEffect(() => {
if (props.draftMessage === props.action.message[0].html) {
return;
}
setDraft(Str.htmlDecode(props.draftMessage));
}, [props.draftMessage, props.action.message]);

useEffect(() => {
// required for keeping last state of isFocused variable
isFocusedRef.current = isFocused;
Expand Down Expand Up @@ -156,9 +149,9 @@ function ReportActionItemMessageEdit(props) {
const debouncedSaveDraft = useMemo(
() =>
_.debounce((newDraft) => {
Report.saveReportActionDraft(props.reportID, props.action, newDraft);
Report.saveReportActionDraft(props.reportID, props.action.reportActionID, newDraft);
}, 1000),
[props.reportID, props.action],
[props.reportID, props.action.reportActionID],
);

/**
Expand Down Expand Up @@ -217,7 +210,7 @@ function ReportActionItemMessageEdit(props) {
*/
const deleteDraft = useCallback(() => {
debouncedSaveDraft.cancel();
Report.saveReportActionDraft(props.reportID, props.action, '');
Report.saveReportActionDraft(props.reportID, props.action.reportActionID, '');
ComposerActions.setShouldShowComposeInput(true);
ReportActionComposeFocusManager.clear();
ReportActionComposeFocusManager.focus();
Expand All @@ -229,7 +222,7 @@ function ReportActionItemMessageEdit(props) {
keyboardDidHideListener.remove();
});
}
}, [props.action, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]);
}, [props.action.reportActionID, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]);

/**
* Save the draft of the comment to be the new comment message. This will take the comment out of "edit mode" with
Expand Down

0 comments on commit df09b28

Please sign in to comment.