Skip to content
Merged
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
Expand Up @@ -166,16 +166,17 @@ function TransactionGroupListItem<TItem extends ListItem>({
const shouldDisplayEmptyView = isEmpty && isExpenseReportType;
const isDisabledOrEmpty = isEmpty || isDisabled;

// Search transactions - handles both refresh (offset 0) and pagination (current offset + pageSize)
const searchTransactions = useCallback(
(pageSize = 0) => {
(pageSize = 0, isRefresh = false) => {
if (!groupItem.transactionsQueryJSON) {
return;
}

search({
queryJSON: groupItem.transactionsQueryJSON,
searchKey: undefined,
offset: (transactionsSnapshot?.search?.offset ?? 0) + pageSize,
offset: isRefresh ? 0 : (transactionsSnapshot?.search?.offset ?? 0) + pageSize,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
});
Expand All @@ -201,15 +202,23 @@ function TransactionGroupListItem<TItem extends ListItem>({
if (!newTransactionID || !isExpanded) {
return;
}
searchTransactions();
searchTransactions(0, true);
}, [newTransactionID, isExpanded, searchTransactions]);

const handleToggle = useCallback(() => {
setIsExpanded(!isExpanded);
if (isExpanded) {
setTransactionsVisibleLimit(CONST.TRANSACTION.RESULTS_PAGE_SIZE);
}
}, [isExpanded]);
setIsExpanded((prev) => {
const newExpandedState = !prev;

if (newExpandedState) {
// Refresh transactions when expanding
searchTransactions(0, true);
} else {
setTransactionsVisibleLimit(CONST.TRANSACTION.RESULTS_PAGE_SIZE);
}

return newExpandedState;
});
}, [searchTransactions]);

const onPress = useCallback(() => {
if (isExpenseReportType || transactions.length === 0) {
Expand Down Expand Up @@ -244,11 +253,9 @@ function TransactionGroupListItem<TItem extends ListItem>({
const onExpandIconPress = useCallback(() => {
if (isEmpty && !shouldDisplayEmptyView) {
onPress();
} else if (groupItem.transactionsQueryJSON && !isExpanded) {
searchTransactions();
}
handleToggle();
}, [isEmpty, shouldDisplayEmptyView, groupItem.transactionsQueryJSON, isExpanded, handleToggle, onPress, searchTransactions]);
}, [isEmpty, shouldDisplayEmptyView, handleToggle, onPress]);

const getHeader = useCallback(
(hovered: boolean) => {
Expand Down
Loading