Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import isEmpty from 'lodash/isEmpty';
import React, {memo, useCallback, useMemo, useState} from 'react';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated';
import type {TupleToUnion} from 'type-fest';
Expand All @@ -25,6 +25,7 @@ import ControlSelection from '@libs/ControlSelection';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
import {navigationRef} from '@libs/Navigation/Navigation';
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
import {generateReportID, getMoneyRequestSpendBreakdown, isIOUReport} from '@libs/ReportUtils';
Expand All @@ -38,7 +39,7 @@ import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import {useMoneyRequestReportContext} from './MoneyRequestReportContext';
import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader';
Expand Down Expand Up @@ -201,6 +202,34 @@ function MoneyRequestReportTransactionList({
[reportActions, sortedTransactions],
);

useEffect(() => {
const lastFullScreenRoute = navigationRef.getRootState()?.routes.findLast((route) => isFullScreenName(route.name));

// Only setActiveTransactionThreadIDs if current full screen report route is this report
if (lastFullScreenRoute?.name !== NAVIGATORS.REPORTS_SPLIT_NAVIGATOR && lastFullScreenRoute?.name !== NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
return;
}

// Check params contain reportID
const lastRoute = lastFullScreenRoute?.state?.routes?.at(-1);
if (!lastRoute?.params || !('reportID' in lastRoute.params)) {
return;
}

// Check lastRoute is a report screen
Comment thread
NikkiWines marked this conversation as resolved.
if (lastRoute?.name !== SCREENS.SEARCH.MONEY_REQUEST_REPORT && lastRoute?.name !== SCREENS.REPORT) {
return;
}

// Check lastRoute params has reportID equal with this reportID
Comment thread
NikkiWines marked this conversation as resolved.
if (lastRoute.params.reportID !== report.reportID) {
return;
}

const sortedSiblingTransactionReportIDs = getThreadReportIDsForTransactions(reportActions, transactions);
setActiveTransactionThreadIDs(sortedSiblingTransactionReportIDs);
}, [report.reportID, reportActions, transactions]);

const dateColumnSize = useMemo(() => {
const shouldShowYearForSomeTransaction = transactions.some((transaction) => shouldShowTransactionYear(transaction));
return shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {findFocusedRoute} from '@react-navigation/native';
import React, {useEffect, useMemo} from 'react';
import React, {useEffect} from 'react';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
Expand All @@ -21,7 +21,7 @@ function MoneyRequestReportTransactionsNavigation({currentReportID}: MoneyReques
const theme = useTheme();

const reportIDsList = getActiveTransactionThreadIDs();
const {prevReportID, nextReportID} = useMemo(() => {
const {prevReportID, nextReportID} = (() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain this change? This looks really bad 😢 @thelullabyy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@blazejkustra I think @thelullabyy explained it here:
#62017 (comment)

if (!reportIDsList) {
return {prevReportID: undefined, nextReportID: undefined};
}
Expand All @@ -32,7 +32,7 @@ function MoneyRequestReportTransactionsNavigation({currentReportID}: MoneyReques
const nextID = currentReportIndex <= reportIDsList.length - 1 ? reportIDsList.at(currentReportIndex + 1) : undefined;

return {prevReportID: prevID, nextReportID: nextID};
}, [currentReportID, reportIDsList]);
})();

const backTo = Navigation.getActiveRoute();

Expand Down