-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 3 commits
9321b99
fe52e3c
ec0c3df
e81bef2
53cbf06
fc7df47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
|
||
/** 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); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line removal caused regression. |
||
|
||
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; | ||
} | ||
|
||
|
@@ -3709,4 +3717,5 @@ export { | |
leaveGroupChat, | ||
removeFromGroupChat, | ||
updateGroupChatMemberRoles, | ||
saveReportDraftCommentWithCallback, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -344,6 +344,20 @@ function ComposerWithSuggestions( | |
[], | ||
); | ||
|
||
useEffect(() => { | ||
const switchToCurrentReport = DeviceEventEmitter.addListener(`switchToCurrentReport_${reportID}`, ({preexistingReportID, callback}) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
* | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel I updated.