Skip to content

Commit

Permalink
fix jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Apr 15, 2024
1 parent 04353fa commit 025dc64
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pages/home/report/UserTypingEventListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe
if (route?.params?.reportID !== reportID) {
return;
}

let interactionTask: ReturnType<typeof InteractionManager.runAfterInteractions> | null = null;
if (isFocused) {
// Ensures subscription event succeeds when the report/workspace room is created optimistically.
// Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming
Expand All @@ -38,7 +38,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe
const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat);

if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) {
InteractionManager.runAfterInteractions(() => {
interactionTask = InteractionManager.runAfterInteractions(() => {
Report.subscribeToReportTypingEvents(reportID);
didSubscribeToReportTypingEvents.current = true;
});
Expand All @@ -53,6 +53,12 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe
});
}
}
return () => {
if (!interactionTask) {
return;
}
interactionTask.cancel();
};
}, [isFocused, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]);

return null;
Expand Down

0 comments on commit 025dc64

Please sign in to comment.