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

Remain draft comment when switching to current chat #41338

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 13 additions & 4 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,10 @@ function saveReportDraftComment(reportID: string, comment: string | null) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, prepareDraftComment(comment));
}

function saveReportDraftCommentWithCallback(reportID: string, comment: string | null, callback: () => void) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, prepareDraftComment(comment)).then(callback);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a separate method for callback alone?

Can we add the callback to existing method and by default callback param empty if not passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Santhosh-Sellavel I updated.

/** Broadcasts whether or not a user is typing on a report over the report's private pusher channel. */
function broadcastUserIsTyping(reportID: string) {
const privateReportChannelName = getReportChannelName(reportID);
Expand Down Expand Up @@ -1202,13 +1206,17 @@ function handleReportChanged(report: OnyxEntry<Report>) {
// In this case, the API will let us know by returning a preexistingReportID.
// We should clear out the optimistically created report and re-route the user to the preexisting report.
if (report?.reportID && report.preexistingReportID) {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line removal caused regression.
We added back in #43633.


let callback = () => {};
// Only re-route them if they are still looking at the optimistically created report
if (Navigation.getActiveRoute().includes(`/r/${report.reportID}`)) {
// Pass 'FORCED_UP' type to replace new report on second login with proper one in the Navigation
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID), CONST.NAVIGATION.TYPE.FORCED_UP);
callback = () => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? ''), CONST.NAVIGATION.TYPE.FORCED_UP);
};
}
DeviceEventEmitter.emit(`switchToCurrentReport_${report.reportID}`, {
preexistingReportID: report.preexistingReportID,
callback,
});
return;
}

Expand Down Expand Up @@ -3709,4 +3717,5 @@ export {
leaveGroupChat,
removeFromGroupChat,
updateGroupChatMemberRoles,
saveReportDraftCommentWithCallback,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
TextInputKeyPressEventData,
TextInputSelectionChangeEventData,
} from 'react-native';
import {findNodeHandle, InteractionManager, NativeModules, View} from 'react-native';
import {DeviceEventEmitter, findNodeHandle, InteractionManager, NativeModules, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import type {useAnimatedRef} from 'react-native-reanimated';
Expand Down Expand Up @@ -344,6 +344,20 @@ function ComposerWithSuggestions(
[],
);

useEffect(() => {
const switchToCurrentReport = DeviceEventEmitter.addListener(`switchToCurrentReport_${reportID}`, ({preexistingReportID, callback}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NAB switchToCurrentReport_ can be switchToPreExistingReport_ . Because that's what the event it is right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated.

if (!commentRef.current) {
callback();
return;
}
Report.saveReportDraftCommentWithCallback(preexistingReportID, commentRef.current, callback);
});

return () => {
switchToCurrentReport.remove();
};
}, [reportID]);

/**
* Find the newly added characters between the previous text and the new text based on the selection.
*
Expand Down
Loading