Skip to content

Commit ffb7d2b

Browse files
authored
Merge pull request Expensify#65625 from software-mansion-labs/@szymczak/fix-empty-report-state-showing
Fix empty report state showing when transactions hasn't been loaded yet
2 parents f2db94f + b1f8df9 commit ffb7d2b

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/CONST/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,9 @@ const CONST = {
13691369
MAX_PREVIEW_AVATARS: 4,
13701370
TRANSACTION_PREVIEW: {
13711371
CAROUSEL: {
1372-
WIDE_WIDTH: 303,
1372+
MIN_WIDE_WIDTH: 303,
13731373
WIDE_HEIGHT: 269,
1374+
MIN_NARROW_WIDTH: 256,
13741375
},
13751376
DUPLICATE: {
13761377
WIDE_HEIGHT: 347,

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
1+
import React, {useCallback, useContext, useDeferredValue, useEffect, useMemo, useRef, useState} from 'react';
22
import {ActivityIndicator, FlatList, View} from 'react-native';
33
import type {LayoutChangeEvent, ListRenderItemInfo, ViewToken} from 'react-native';
44
import Animated, {useAnimatedStyle, useSharedValue, withDelay, withSpring, withTiming} from 'react-native-reanimated';
@@ -115,6 +115,11 @@ function MoneyRequestReportPreviewContent({
115115
shouldShowBorder = false,
116116
onPress,
117117
}: MoneyRequestReportPreviewContentProps) {
118+
const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`, {canBeMissing: true, allowStaleData: true});
119+
const shouldShowLoading = !chatReportMetadata?.hasOnceLoadedReportActions && transactions.length === 0;
120+
// `hasOnceLoadedReportActions` becomes true before transactions populate fully,
121+
// so we defer the loading state update to ensure transactions are loaded
122+
const shouldShowLoadingDeferred = useDeferredValue(shouldShowLoading);
118123
const lastTransaction = transactions?.at(0);
119124
const shouldShowEmptyPlaceholder = transactions.length === 0;
120125
const theme = useTheme();
@@ -408,7 +413,7 @@ function MoneyRequestReportPreviewContent({
408413

409414
// The button should expand up to transaction width
410415
const buttonMaxWidth =
411-
!shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewCarouselStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.WIDE_WIDTH
416+
!shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewCarouselStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH
412417
? {maxWidth: reportPreviewStyles.transactionPreviewCarouselStyle.width}
413418
: {};
414419

@@ -707,11 +712,14 @@ function MoneyRequestReportPreviewContent({
707712
)}
708713
</View>
709714
</View>
710-
{!currentWidth ? (
715+
{!currentWidth || shouldShowLoading || shouldShowLoadingDeferred ? (
711716
<View
712717
style={[
713718
{
714719
height: CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.WIDE_HEIGHT,
720+
minWidth: shouldUseNarrowLayout
721+
? CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_NARROW_WIDTH
722+
: CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH,
715723
},
716724
styles.justifyContentCenter,
717725
styles.mtn1,

src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function MoneyRequestReportPreview({
5858
() => StyleUtils.getMoneyRequestReportPreviewStyle(shouldUseNarrowLayout, transactions.length, currentWidth, currentWrapperWidth),
5959
[StyleUtils, currentWidth, currentWrapperWidth, shouldUseNarrowLayout, transactions.length],
6060
);
61-
6261
const shouldShowPayerAndReceiver = useMemo(() => {
6362
if (!isIOUReport(iouReport) && action.childType !== CONST.REPORT.TYPE.IOU) {
6463
return false;

src/styles/utils/getMoneyRequestReportPreviewStyle/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const componentsSpacing = {
1313

1414
const NEXT_TRANSACTION_PEEK = 32;
1515
const CAROUSEL_MAX_WIDTH_WIDE = CONST.REPORT.CAROUSEL_MAX_WIDTH_WIDE;
16-
const TRANSACTION_WIDTH_WIDE = CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.WIDE_WIDTH;
16+
const TRANSACTION_WIDTH_WIDE = CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH;
1717
const CAROUSEL_ONE_SIDE_PADDING = componentsSpacing.wrapperStyle.padding;
1818
const CAROUSEL_GAP = spacing.gap2.gap;
1919

0 commit comments

Comments
 (0)