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

Refactor shouldFetchReport function to reduce updates #56093

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions src/libs/shouldFetchReport.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {OnyxEntry} from 'react-native-onyx';
import type Report from '@src/types/onyx/Report';
import type ReportMetadata from '@src/types/onyx/ReportMetadata';

export default function shouldFetchReport(report: OnyxEntry<Report>, reportMetadata: OnyxEntry<ReportMetadata>) {
export default function shouldFetchReport(report: OnyxEntry<Report>, isOptimisticReport?: boolean) {
// If the report is optimistic, there's no need to fetch it. The original action should create it.
// If there is an error for creating the chat, there's no need to fetch it since it doesn't exist
return !reportMetadata?.isOptimisticReport && !report?.errorFields?.createChat;
return !isOptimisticReport && !report?.errorFields?.createChat;
}
4 changes: 2 additions & 2 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
return;
}

if (!shouldFetchReport(report, reportMetadata)) {
if (!shouldFetchReport(report, reportMetadata.isOptimisticReport)) {
return;
}
// When creating an optimistic report that already exists, we need to skip openReport
Expand All @@ -534,7 +534,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
}

fetchReport();
}, [reportIDFromRoute, isLoadingApp, report, reportMetadata, fetchReport]);
}, [reportIDFromRoute, isLoadingApp, report, fetchReport, reportMetadata.isOptimisticReport]);

const dismissBanner = useCallback(() => {
setIsBannerVisible(false);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function ReportActionsView({
const reportID = report.reportID;
const isReportFullyVisible = useMemo((): boolean => getIsReportFullyVisible(isFocused), [isFocused]);
const openReportIfNecessary = () => {
if (!shouldFetchReport(report, reportMetadata)) {
if (!shouldFetchReport(report, reportMetadata?.isOptimisticReport)) {
return;
}

Expand Down